Hello, I’m exploring Anaconda.cloud notebooks as an addition to local notebooks or Github codespaces.
With an anaconda notebook is there a way to store API keys in a cloud storage .env file that can be invoked with python-dotenv?
Alternatively, does the free or starter tier support environment variables through a secrets manager (e.g. GitHub’s secrets and variables manager for codespaces)?
thanks.
Hey @jefferson1, thanks for considering Anaconda and welcome to the Anaconda community!
We haven’t built a custom secrets manager extension yet, but this is something we’re considering (I’m the product manager so always looking out for feature requests!), so I’m keen to understand your ideal workflow. Assuming as your secrets are already in GitHub you would want to connect directly to those and just manage them in one place?
The dotenv package is available in all of our anaconda-ai-2024.04-py10
environment, so you should be able to upload a .env file and work as you would locally.
If you wanted to use the same .env file both locally and on our cloud notebooks, you can use the Projects feature we added recently. Click the Anaconda logo in the left side bar and Create a Project with the secret and the .env
file in. There looks to be a bug in the saving of that file right now but we’ll get that fixed ASAP.
Then as seen in the screenshot below, if you create a notebook in the same project you can start using those secret keys in your notebook. The only thing to be careful of here is that the .env file will be included in the project if you decided to share it with others.
The other thing I’ve seen used out the box is the getpass
python module, included in the screenshot as well, not sure if you’ve come across that and might solve your use case?
Let me know how you get on!
Jack
Hello Jack,
thanks for the quick reply! In particular, for pointing me at the right conda environment and kernel where you have python-dotenv installed.
I played around with a test file using the Projects feature (which I like!). I ran into the “save” bug you described. I wound up working around it by uploading my test env file with the name of env.txt. I then ran os.rename(‘env.txt’, ‘.env’) to name it correctly. Having done so, load_dotenv started working as expected.
So, I got it working! I’ll look forward to the bug fix as it is released.
In answer to your question, I suppose the ideal workflow would be a secrets manager that is local to anaconda.cloud. That way, I can just pull them in as env variables – that’s how I do it today with a GitHub codespace.
Btw: I’m really impressed with the Anaconda Assistant and how well it integrates with a Jupyter Notebook. Well done!
Hi,
No problem and I find it slightly odd that package isn’t everywhere as it’s quite useful.
Your solution sounds like a more effective workaround to what I had! Will post back here once we’ve got a proper fix in place.
We were considering using some UI similar to our Code Snippets tool, so you could add API keys, and then click play to add them to the active kernel. So in this example I could create the api_key secret, then click the play button to add it to any notebook I’m using (maybe this could happen automatically?). Obviously without the ability to print the secret value into the notebook!
Glad you’re enjoying the Anaconda Assistant, some cool new features coming in the next few weeks so keep an eye out for those!
Thanks,
Jack