set-env-colab-kaggle-dotenv
Set an environ variable from colab, kaggle or dotenv (search default .env/dotenv/env)
Why set_env
colab and kaggle both provide a way to manage secrets (typically API tokens).
set_env is mainly for running ipynb (jupyter notebook) files in colab/kaggle or cloud instance when we need to set an environ variable, for example, HF_TOKEN to download models or datasets from huggingdace hub, other scenarios include WANDB_API_KEY or NGROK_AUTHCODE or OPENAI_API_KEY etc.
When running an ipynb in a cloud instance, we may use dotenv (pip install python-dotenv) to set environ varibales based on .env.
Install it
pip install set-env-colab-kaggle-dotenv
Setup Secrets or Upload .env
-
In colab, set Secrets
-
In kaggle, set Add-ons/Secrets
-
In other jupyter environ/cloud instance, upload .env, with contents, e.g.
HF_TOKEN=...
WANDB_API_KEY=...
In some cases, files start with a dot are not allowed. Rename .env to dotenv or env instead, set_env will auto-search for .env, dotenv and env.
Use it
from set_env import set_env
# e.g.
set_env("HF_TOKEN")
set_env("WANDB_API_KEY")
set_env("NGROK_AUTHCODE")
Sometimes we want to set HF_TOKEN to HF_TOKEN_W (with write-permission).
from set_env import set_env
set_env(env_var="HF_TOKEN", source_var="HF_TOKEN_W")
This is effectively equivalent to os.environ["HF_TOKEN"] = get_secret("HF_TOKEN_W") when in colab or kaggle, or os.environ["HF_TOKEN"] = dotenv.dotenv_values().get("HF_TOKEN_W").
Metadata
Release files for set-env-colab-kaggle-dotenv 0.1.4
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 | Actions |
|---|---|---|---|---|
| set_env_colab_kaggle_dotenv-0.1.4.tar.gz | 142.2 kB | Without provenance | Details for set_env_colab_kaggle_dotenv-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| set_env_colab_kaggle_dotenv-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for set_env_colab_kaggle_dotenv-0.1.4-py3-none-any.whl |
Total release size: 146.1 kB
Release files / set_env_colab_kaggle_dotenv-0.1.4.tar.gz
| Download URL | set_env_colab_kaggle_dotenv-0.1.4.tar.gz |
|---|---|
| Size | 142.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91e0977a45ae4d776eac18bf887cbcfac8437921051c27cd58ae3c4caa571cab
|
|
BLAKE2b-256 checksum How to use checksums |
c7b6f7c54f1f28dda8fa2299fb2bd962cfdc77d6db4fe700862ce34d56e88b3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / set_env_colab_kaggle_dotenv-0.1.4-py3-none-any.whl
| Download URL | set_env_colab_kaggle_dotenv-0.1.4-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
090a1173644e9d6c23da47c0a1ec18cee13b38bacd79863ceabf68e21f69fdd7
|
|
BLAKE2b-256 checksum How to use checksums |
61efeb4a519f321b49d47faf8245442641aa27334dd5a82018bf11300bebc3a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for set-env-colab-kaggle-dotenv 0.1.4
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.