Skip to main content

envhint

Typed environment variable loading via class declaration. Requires only strcoerce.

The problem

# Scattered across every project:
PORT    = int(os.environ.get("PORT", "8080"))
DEBUG   = bool(os.environ.get("DEBUG", "false"))  # bug — always True
HOSTS   = os.environ.get("ALLOWED_HOSTS", "").split(",")
TIMEOUT = timedelta(minutes=int(os.environ.get("TIMEOUT_MINUTES", "5")))

Install

pip install envhint

Usage

from envhint import Env
from datetime import timedelta

class Settings(Env):
    port: int = 8080
    debug: bool = False
    db_url: str                        # required — raises EnvError if absent
    allowed_hosts: list[str] = []
    request_timeout: timedelta = timedelta(seconds=30)

settings = Settings()

print(settings.port)            # 8080  (int, not "8080")
print(settings.debug)           # False (not True like bool("false"))
print(settings.allowed_hosts)   # ["api.example.com", "admin.example.com"]

Set via environment:

PORT=9000
DEBUG=false
DB_URL=postgresql://localhost/mydb
ALLOWED_HOSTS=api.example.com,admin.example.com
REQUEST_TIMEOUT=2m30s

All errors reported at once

class Settings(Env):
    db_url: str
    secret_key: str
    api_key: str

Settings(_env={})
# EnvError: Environment configuration errors:
#   DB_URL: required but not set
#   SECRET_KEY: required but not set
#   API_KEY: required but not set

Testing without patching os.environ

def test_my_feature():
    settings = Settings(_env={
        "DB_URL": "postgresql://localhost/test",
        "SECRET_KEY": "test-secret",
    })
    assert settings.port == 8080  # default

.env file support

settings = Settings(_env_file=".env")
# Real env vars take priority over .env file values

Supported types

Annotation Parsed from
str passthrough
int "42" → 42
float "3.14" → 3.14
bool "true/false/yes/no/1/0/on/off"
list[str] "a,b,c" → ["a", "b", "c"]
timedelta "5m", "2h30m", "1d"
Optional[X] absent → None, present → coerced as X

License

MIT

Metadata

Release files for envhint 0.1.0

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

Source distribution (sdist)

Source distribution for envhint 0.1.0
File Size Uploaded
envhint-0.1.0.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envhint 0.1.0
File Interpreter ABI Platform
envhint-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / envhint-0.1.0.tar.gz

Download URL envhint-0.1.0.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f59f9f87981a0b5d966ab41f8dfbd54ba33d8ae01433139a0fad7667db5041ac
BLAKE2b-256 checksum
How to use checksums
2e737c419b831b07114e2eee971cf6b0a8caa5fd65206645128d73eaaf9a6eb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release files / envhint-0.1.0-py3-none-any.whl

Download URL envhint-0.1.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
388db55eb976c740c34d081236b38b85e5f4a16f2311ac459fe10f5e89a38165
BLAKE2b-256 checksum
How to use checksums
c708f9aaedc709111f87c0d7ff7b6f67c7f1f02cdec2268b1972785d58b1ebf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

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