Read environment variables from Jupyter

I have some environment variables set in startup.py and in the system.
I want to change panel toolbar button value in accordance for the env.

How can i read the env from the typescript code?

If I am understanding you correctly, the TypeScript code would need to make an API call to the server and access the environment using Python’s os.environ and send the result back to the client. Is that what you are trying to do?

1 Like

Yes. This is exactly what I need

I can’t seem to figure out how to do it.

Please consider working through the Hello World example and the Server Hello World example: GitHub - jupyterlab/extension-examples: JupyterLab Extensions by Examples

I’ll check back to see if I can answer questions that come up.

1 Like

So i need to create a Server-Client extension like in here extension-examples/advanced/server-extension at 2.x · jupyterlab/extension-examples · GitHub ?

The only problem I encounter is that the cookie-cutter does not add the server code for lab2

Just for clarification, is it correct that you are targeting JL 2.0 and not JL 3.0?

Yes, if you add the call to os.environ to one of the methods of the RouteHandler you can return its contents to the client.

Please let me know if you still need help, as I will try to put together a minimal working example for you.

1 Like

Yes, I am using JL2.
I will follow the instructions in the github repo and report back for any problems.

Thanks!

I cant seems to install it locally. instructions are not working in the README

Are you able to push your work to a public GitHub repository, so I can clone it and test it?

My bad. today all works!