Set env (e.g. HF_TOKEN) from colab/kaggle secrets or dotenv .env env files
Project description
python-setenv
Set an environ variable from colab, kaggle or dotenv (search default .env/dotenv/env)
Why python-setenv
colab and kaggle both provide a way to manage secrets (typically API tokens).
python-setenv 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 python-setenv
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, setenv will auto-search for .env, dotenv and env.
Use it
from setenv import setenv
# e.g.
setenv("HF_TOKEN")
setenv("WANDB_API_KEY")
setenv("NGROK_AUTHCODE")
Sometimes we want to set HF_TOKEN to HF_TOKEN_W (with write-permission).
from setenv import setenv
setenv(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").
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_setenv-0.0.2.tar.gz.
File metadata
- Download URL: python_setenv-0.0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a83b9ae87640ce49512ad54ffceb342c4bbcce13f906c0e26a18fe155e507e8
|
|
| MD5 |
f9210a5a988994e665d7e1850d2496c7
|
|
| BLAKE2b-256 |
f1174da0692c10c1dd0f2d19e67ea5804583d27a3cf0bddd6ffe3f264b5b9e0b
|
File details
Details for the file python_setenv-0.0.2-py3-none-any.whl.
File metadata
- Download URL: python_setenv-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0478df5500a6d7207d4ed592f424ba94482aced4b23029b488d272cfaad37fd6
|
|
| MD5 |
8c0b2345081be51378dff51a43b074b9
|
|
| BLAKE2b-256 |
121e22cb3db3cc20b589d7c277707a280e47d169552cf5aa4c37fca1bd5d0d3b
|