Skip to main content

Pydantic v2 mixin to load settings from environment variables with robust casting

Project description

envmix

Typed environment loader for Pydantic v2 models.

Features

  • Simple: from_env() fills fields from overrides > env vars > defaults
  • Typed: ships py.typed; works nicely with type checkers
  • Robust casting: JSON-first via TypeAdapter; CSV and k=v fallbacks

Install

pip install envmix

Quick start

from pydantic import BaseModel
from envmix import EnvMixModel

class DB(BaseModel):
    host: str
    port: int

class Settings(EnvMixModel):
    __env_prefix__ = "APP_"
    host: str = "127.0.0.1"
    port: int = 8080
    debug: bool = False

# export APP_PORT=5000 APP_DEBUG=true
s = Settings.from_env()
print(s.port)  # 5000
print(s.debug) # True

Custom env key per field

from pydantic import Field

class Settings(EnvMixModel):
    server_host: str = Field("0.0.0.0", json_schema_extra={"env": "SERVER_HOST"})

License MIT

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

envmix-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

envmix-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file envmix-0.1.1.tar.gz.

File metadata

  • Download URL: envmix-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for envmix-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5eeccf1b2fa326aeb4a9830cae929b820d7c967759c42636e583484b575453ec
MD5 b610be52f73d6e6428517f4dc58659d9
BLAKE2b-256 c59ac16d9703dc73c6f8ee5c2291aec204d9896c92d9bedb42a0846a4ece7ab4

See more details on using hashes here.

File details

Details for the file envmix-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: envmix-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for envmix-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a453fe53846fcb9a1a757478429a0aaf5e88ee947acc456d9099739497cf5325
MD5 3a5bf77701980ea31e9fc1fc92fac9f3
BLAKE2b-256 a762756e485e696202b85c935e794ac795381f4f1adee78b41f3c5392762fca3

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