# Python equivalent of flow.set() and flow.get()

**URL:** <https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187>\
**Category:** General\
**Tags:** python\
**Created:** [2 July 2024 15:35 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187 "2024-07-02T15:35:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [2 July 2024 15:35 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/1 "2024-07-02T15:35:09Z")

</div>

Hi. I'm new to Node Red. Sorry, I'm using Python... I want to be able to share variables between nodes and all I can find is how to get data from sys.argv (so sent as a trigger from another node). My triggers to various nodes will contain data specific to objects I want to status or control and I can pass that using sys.argv but I want to access other variables that could be common to all nodes in the flow (e.g. API access token). In some nodeJS examples I found flow.set() and flow.get() methods but I could not find any Python equivalent. I really don't want to have to store these in a bunch of text files....

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 July 2024 15:53 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/2 "2024-07-02T15:53:11Z")

</div>

Welcome to the forum @Ouagadougou.

No need to apologise for using python.  
But how are you planning to use it with Node-red?

The most obvious way is to call your python script[s] via the Exec node of Node-red.  
That does allow you to pass values to the script as command line parameters.  
For static data like API keys you might consider Environment variables.

I think you may have some Node-red terminology confused, and as a newcomer to Node-red you might find these introductory videos useful: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are made by the developers of node-red.

Note that Node-red is built upon passing a collection of related data as a complete "message". Although context variables are available, it might be a mistake to leap straight to using them rather than message properties.

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [2 July 2024 16:09 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/3 "2024-07-02T16:09:32Z")

</div>

Thanks for the quick reply and for the introductory videos. I thought I could use a change node to give me access to the variables I needed and tried to add this and another trigger to a node block but I could see variables were only passed by the triggering node. I will have a look through the videos and take you up on your suggestion to use environment variables.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [2 July 2024 18:58 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/4 "2024-07-02T18:58:45Z")

</div>

Your description of what you are trying to do really does not make any sense, so it is quite possible that we don't understand at all what you are trying to do. If you want further help please explain what you are trying to do with python in relation to node-red.

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [3 July 2024 07:11 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/5 "2024-07-03T07:11:27Z")

</div>

Hi Colin  
I have APIs that I need to access and they need a valid token. The APIs will be triggered using data such as the workload being controlled and the parameters to send to it. I don't want to have to request a token every time I make an API call. I can get a token that is valid for 24 hours and valid for any node making API calls on that platform so I want to put the token information somewhere that it can be accessed by any node accessing APIs on that platform.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 July 2024 09:16 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/6 "2024-07-03T09:16:36Z")

</div>

So what has that got to do with Python?

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [3 July 2024 10:20 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/7 "2024-07-03T10:20:01Z")

</div>

I'm using Python, I don't know nodeJS and Python doesn't have a simple way to access flow variables or flow variables (e.g. you can't say flow.get() or flow.set()).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 July 2024 11:06 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/8 "2024-07-03T11:06:58Z")

</div>

So what has the question got to do with Node Red? You did not answer questions about how you are using python with node red.

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [3 July 2024 13:43 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/9 "2024-07-03T13:43:47Z")

</div>

I already have a number of Python scripts that I use in Jupyter notebooks to do various API actions. Each time I need to modify the script to get it to control a specific workload within the platform I am controlling. I thought of using Node Red as a more graphic way of doing this where I can have pre-prepared configurations that I can pass to the nodes containing the scripts rather than modifying scripts each time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 July 2024 14:40 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/10 "2024-07-03T14:40:03Z")

</div>

> [@Ouagadougou](#):
>
> I thought of using Node Red as a more graphic way of doing this where I can have pre-prepared configurations that I can pass to the nodes containing the scripts rather than modifying scripts each time.

What node are you using that contains a python script?

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [3 July 2024 15:12 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/11 "2024-07-03T15:12:02Z")

</div>

I'm using node-red-contrib-pythonshell. In any case, I resolved my issue by using a database to store any data that needs to be shared between nodes.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [3 July 2024 15:34 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/12 "2024-07-03T15:34:38Z")

</div>

Have you seen the example Jupyter Tools on [flows.nodered.org](https://flows.nodered.org/flow/35d7143ff6b0c96becfbcbd6b525c4b3) ?

It seems to offer python scripting within Node-red, may be relevant to your requirements.

---

<div class="post-metadata">

**Author:** ![Ouagadougou](https://avatars.discourse-cdn.com/v4/letter/o/a587f6/32.png) [@Ouagadougou](https://discourse.nodered.org/u/Ouagadougou)\
**Post date:** [3 July 2024 15:52 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/13 "2024-07-03T15:52:24Z")

</div>

Thanks jbudd. I'll give it a try.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 July 2024 16:27 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/14 "2024-07-03T16:27:54Z")

</div>

> [@Ouagadougou](#):
>
> I'm using node-red-contrib-pythonshell. I

Had you told us that in the first post it would have been much easier to understand your question.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 July 2024 16:27 UTC](https://discourse.nodered.org/t/python-equivalent-of-flow-set-and-flow-get/89187/15 "2024-07-17T16:27:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
