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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_setenv-0.0.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_setenv-0.0.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file python_setenv-0.0.3.tar.gz.

File metadata

  • Download URL: python_setenv-0.0.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.16

File hashes

Hashes for python_setenv-0.0.3.tar.gz
Algorithm Hash digest
SHA256 fac575f8455393611005ffac636fd74e632ca47561e30e1399a1bb0ab8778640
MD5 87fccffe1b7847e6a24eeeef263d26a3
BLAKE2b-256 ec0e8fc15cbdb6fa745bd5b3aca3171c917b8fcaa058d1a0cd9ffc580ab0446f

See more details on using hashes here.

File details

Details for the file python_setenv-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_setenv-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b049f2ebbb7f5956804b5abd43310f9a633c57e56617bc1743fda3a7b3d0fc00
MD5 af451eaad95c827546b48d8b137107ba
BLAKE2b-256 cc3f03fb105956a74e05c60e26574f135da76c98ac06250b74d28bb41e4b5fcb

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.0

1 file

This release

0.0.3 This release

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page