Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access global objects from Python #35

Open
corndog2000 opened this issue Oct 22, 2024 · 1 comment
Open

Access global objects from Python #35

corndog2000 opened this issue Oct 22, 2024 · 1 comment

Comments

@corndog2000
Copy link

corndog2000 commented Oct 22, 2024

I know that currently you can access the node-red msg object from the python code. I was wonder what it would take to read/write to node-red global variables too.

@404background
Copy link
Owner

Thank you @corndog2000 for your comments on the issue!

For now, only the msg object can be accessed from the node.
Access to msg objects was implemented in #6 .
The following is implemented in node/venv.js as an argument when executing Python.

const message = Buffer.from(JSON.stringify(msg)).toString('base64')
const args = [
  '-c',
  `import base64;import json;msg=json.loads(base64.b64decode(r'${message}').decode('utf-8'));exec(open(r'${filePath}', encoding='utf-8').read())`,
]

It would be more convenient for future use to be able to access flow and global objects as well.
I will try to implement that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants