Skip to main content

python-setenv

pytestpythonCode style: blackLicense: MITPyPI version

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").

Metadata

Release files for python-setenv 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-setenv 0.0.3
File Size Uploaded
python_setenv-0.0.3.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-setenv 0.0.3
File Interpreter ABI Platform
python_setenv-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / python_setenv-0.0.3.tar.gz

Download URL python_setenv-0.0.3.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
fac575f8455393611005ffac636fd74e632ca47561e30e1399a1bb0ab8778640
BLAKE2b-256 checksum
How to use checksums
ec0e8fc15cbdb6fa745bd5b3aca3171c917b8fcaa058d1a0cd9ffc580ab0446f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release files / python_setenv-0.0.3-py3-none-any.whl

Download URL python_setenv-0.0.3-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b049f2ebbb7f5956804b5abd43310f9a633c57e56617bc1743fda3a7b3d0fc00
BLAKE2b-256 checksum
How to use checksums
cc3f03fb105956a74e05c60e26574f135da76c98ac06250b74d28bb41e4b5fcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release history Release notifications | RSS feed

0.1.0

1 release file

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page