colab-env
Outline
This Python package handles environment variables in Google Colab. Environment variables are an important infrastructure component e.g. containing secrets such as API keys that ought not to be included directly in the codebase. At the time of writing, however, Google Colab does not have built-in support for environment variables.
Our solution is to use the python-dotenv package in concert with Colab's built in authorisation tool for Google Drive. The package will attempt to
- mount Google Drive locally
- load environment variables from a file called
vars.env
Usage
To load environment variables using colab-env you should include the following code at the top of your Colab notebook:
!pip install colab-env -qU
import colab_env
This will usually open the google.colab.drive.mount authentication flow. We use this authentication step to protect any secrets in vars.env.
Remember not to expose these secrets in the outputs of any cells!
When the authentication challenge is passed, the environment variables will either be loaded into the Google Colab environment, or vars.env will be created in your Google Drive.
To modify environment variables using colab-env you should do the following:
!pip install colab-env -qU
from colab_env import envvar_handler
... and then use envvar_handler's add_env and del_env methods to add/modify and delete environment variables respectively from vars.env.
Take it for a test-drive
Simply open up colab-env/colab_env_testbed.ipynb in Google Colab and try it out!
Contributors
Paddy Alton (paddy.alton@apolitical.co)
(with thanks to the Apolitical engineering team for assistance and review)
Metadata
Release files for colab-env 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| colab-env-0.2.0.tar.gz | 4.7 kB | Without provenance | Details |
Release files / colab-env-0.2.0.tar.gz
| Download URL | colab-env-0.2.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7995146cc5cd66a96aa07a2fce7178f0af45073787bc56f25e3e4480d7e506b7
|
|
BLAKE2b-256 checksum How to use checksums |
9d661845bc28d685894e6e203cfb2bdd9d19c86926d7a6f765e9497e218ab304
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.4.2 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5
|
Security for colab-env 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.