Skip to main content

Creates a class used to query environmental variables with typehinting a conversion to basic Python types.

Project description

env-proxy

PyPI version Python versions License CI Coverage

env-proxy reads environment variables with type hints, type conversion, and a declarative configuration layer. Define your env-driven config once as a typed class, then access fields like any other attribute — with eager validation, optional freezing for performance, and sample .env generation included.

Install

# Using pip
pip install env-proxy

# Using Poetry
poetry add env-proxy

Supports Python 3.10+.

Quickstart

import os
from env_proxy import EnvConfig, Field

os.environ["MYAPP_DEBUG"] = "true"
os.environ["MYAPP_DATABASE_URL"] = "sqlite:///data.db"
os.environ["MYAPP_CACHE_BACKENDS"] = "redis,memcached"

class MyConfig(EnvConfig):
    env_prefix: str = "MYAPP"
    debug: bool = Field(description="Enable debug mode", default=False)
    database_url: str = Field(description="Database connection URL")
    cache_backends: list[str] = Field(description="Cache backends", type_hint="list")

config = MyConfig()
config.validate()   # fail fast on missing/bad env values
config.freeze()     # optional: turn reads into a dict lookup

print(config.debug)              # True
print(config.database_url)       # "sqlite:///data.db"
print(config.cache_backends)     # ["redis", "memcached"]

For one-off lookups without a full config class, the lower-level EnvProxy exposes typed getters (get_str, get_int, get_bool, get_list, get_json, …):

from env_proxy import EnvProxy

proxy = EnvProxy(prefix="MYAPP")
proxy.get_int("port", default=8080)

Documentation

Full documentation — tutorial, how-to guides, reference, and the auto-generated API — lives at https://tomasvotava.github.io/env-proxy/.

Quick links:

Contributing

make ci runs every check that CI runs (ruff format --check, ruff check, mypy, pytest). make docs-serve previews the docs at http://127.0.0.1:8000.

Commit messages follow Conventional Commits; the pre-commit commit-msg hook enforces this locally.

Releasing

Releases are driven by commitizen. From master:

poetry run cz bump      # bumps pyproject.toml, appends to CHANGELOG.md, commits, tags
git push --follow-tags  # pushes the bump commit and the new tag together

Pushing the tag triggers .github/workflows/release.yml, which builds the distribution, creates a GitHub Release whose body is the matching CHANGELOG.md section, and publishes to PyPI.

License

env-proxy is open-source under the MIT License. See LICENSE.md.

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

env_proxy-1.7.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

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

env_proxy-1.7.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file env_proxy-1.7.0.tar.gz.

File metadata

  • Download URL: env_proxy-1.7.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1018-azure

File hashes

Hashes for env_proxy-1.7.0.tar.gz
Algorithm Hash digest
SHA256 6b8d8fee05abbd86d36e2823697a51ac166dc5c4e1483c235d7bfc4adaf8c23c
MD5 ec14aa55c08e1315b0998ff6019d17f4
BLAKE2b-256 8ffc5075185036cce92517c023461573a50e7b45ad2222123f4e9aa441c92e51

See more details on using hashes here.

File details

Details for the file env_proxy-1.7.0-py3-none-any.whl.

File metadata

  • Download URL: env_proxy-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/6.17.0-1018-azure

File hashes

Hashes for env_proxy-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbc41cace75d27466e4e7a406ffa53b78fcfc77bbfc9d436f1df59355d2ab74e
MD5 89c794a970ebf513049da93539c5929f
BLAKE2b-256 344603c185cbc1bf1554e8560fc3cc89ce8f7466f3f7a61648961674cfc58b87

See more details on using hashes here.

Supported by

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