Set an environ variable in colab/kaggle/dotenv(.env/dotenv/env)
Project description
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")
.
Project details
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
File details
Details for the file set_env_colab_kaggle_dotenv-0.1.3.tar.gz
.
File metadata
- Download URL: set_env_colab_kaggle_dotenv-0.1.3.tar.gz
- Upload date:
- Size: 141.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 374fde162bda995a74d62d9d8bb00b748b5d189c2702f0d8f52a839cb9120058 |
|
MD5 | 15c09c2db2d888a58aec6c08853fbe89 |
|
BLAKE2b-256 | f01cdfe34dbdd88420a8302c58eb7285f65756abf745d488b7b3faab60968fb4 |
File details
Details for the file set_env_colab_kaggle_dotenv-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: set_env_colab_kaggle_dotenv-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29239a2daec99e5ed68568c0a85b375f4f9152eae359b3908c6e1644b0bd9122 |
|
MD5 | 7e0b10983cf98d484210cf65f824388a |
|
BLAKE2b-256 | ca5cbb6c8345d15fb6c82606793aa8564730365985038f28e27f02024dd8f048 |