No project description provided
Project description
dotenv-utils
A tiny, self-contained package for parsing environment variables. Works well in conjunction with python-dotenv.
For a full-fledged solution, look at environs instead.
Docs
You can find the documentation for the project online.
Installation
You can install the package via pip, with pip install dotenv-utils.
Usage
Basic usage looks like this:
# Load environment variables with python-dotenv (optional):
from dotenv import load_dotenv
load_dotenv()
# Basic functions to parse values and lists of values
from dotenv_utils import get_var, get_var_list
# Read a required variable (raises if missing):
SECRET_KEY: str = get_var("SECRET_KEY") # e.g., "s3cr3t"
# Read an optional variable with default:
PROTOCOL: str = get_var("PROTOCOL", default="tcp") # may be undefined
# Use a cast to set the value type:
PORT: int = get_var("PORT", cast=int) # e.g., "22"
# Read a list from a semicolon-separated variable:
ALLOWED_HOSTS: list[str] = get_var_list( # e.g., "example.com; my.domain.tld"
"ALLOWED_HOSTS",
default=["localhost"],
)
# By default, values are split by `;`. Pass, e.g., `sep=","` to use commas.
PORTS: list[int] = get_var_list( # e.g., "22, 53, 80"
"PORTS",
sep=",", # use commas
cast=int, # cast elements to int
)
# Examples of useful convenience functions from `dotenv_utils.casts`:
from dotenv_utils.casts import str2bool, str2timedelta
from datetime import timedelta
# The `str2bool` function will handle common ways to specify true/false as strings
DEBUG: bool = get_var("DEBUG", default=False, cast=str2bool)
# You can also use more exotic types - check the docs to see what's available
default_ttl = str2timedelta("5m") # default arg is not cast - similar to argparse
CACHE_TTL: timedelta = get_var("CACHE_TTL", default=default_ttl, cast=str2timedelta)
Contributing
Contributions are welcome! To get started:
- Fork the repository and clone your fork.
- Create and activate a virtual environment.
python -m venv .venv source .venv/bin/activate
- Install development dependencies in editable mode.
python -m pip install -e .[dev]
- Run the test suite and linters, and build[^docs_reqs] the documentation.
# see make help for all available rules make chores # outputs are logged in logs/ make docs # output goes to docs/build
The chores should not give you any complaints. - If everything looks good, you can open a pull request. Use Conventional Commits in your commit messages.
[^docs_reqs]: Documentation is built with Sphinx. Certain LaTeX packages might be required for the PDF.
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 dotenv_utils-0.2.1.tar.gz.
File metadata
- Download URL: dotenv_utils-0.2.1.tar.gz
- Upload date:
- Size: 13.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f9e4845ff1c76892484dab902db281c8c9588b88f5160f1622873fa5d54930b
|
|
| MD5 |
c660e8b94114265b4f6b9fca3760510f
|
|
| BLAKE2b-256 |
2bc98abcda9d350011087c868198cbf3190b719343d5a896b67fe08c7bb47adc
|
Provenance
The following attestation bundles were made for dotenv_utils-0.2.1.tar.gz:
Publisher:
build.yml on FynnFreyer/dotenv-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenv_utils-0.2.1.tar.gz -
Subject digest:
1f9e4845ff1c76892484dab902db281c8c9588b88f5160f1622873fa5d54930b - Sigstore transparency entry: 623398986
- Sigstore integration time:
-
Permalink:
FynnFreyer/dotenv-utils@0123a1cd08f8b829f460fbf3a5d82db7d03d2d9c -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/FynnFreyer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@0123a1cd08f8b829f460fbf3a5d82db7d03d2d9c -
Trigger Event:
push
-
Statement type:
File details
Details for the file dotenv_utils-0.2.1-py3-none-any.whl.
File metadata
- Download URL: dotenv_utils-0.2.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd51f6c2315428c3c8e7dcedd279934161eb59796983770e8f1fe6c67c1b508c
|
|
| MD5 |
85a3177ecbb176c04e878bbf51909090
|
|
| BLAKE2b-256 |
27a39891bf1896e418c09f3915c1eb936e07f8be7429fbf97b9b7537022560f6
|
Provenance
The following attestation bundles were made for dotenv_utils-0.2.1-py3-none-any.whl:
Publisher:
build.yml on FynnFreyer/dotenv-utils
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dotenv_utils-0.2.1-py3-none-any.whl -
Subject digest:
dd51f6c2315428c3c8e7dcedd279934161eb59796983770e8f1fe6c67c1b508c - Sigstore transparency entry: 623398989
- Sigstore integration time:
-
Permalink:
FynnFreyer/dotenv-utils@0123a1cd08f8b829f460fbf3a5d82db7d03d2d9c -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/FynnFreyer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@0123a1cd08f8b829f460fbf3a5d82db7d03d2d9c -
Trigger Event:
push
-
Statement type: