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.2.tar.gz (5.2 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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for envmix-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1c429799fdb929762875b8b9fd8cd0b0b84c17b7156ced57e9b6f2aa5f0a66c4
MD5 7c2da06b0fe7f00704ca5dc54bf05c40
BLAKE2b-256 6df30f803f6709141ed2f8dd363a6e070a0505f0eaad26ebb441d6b1eca7ca33

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for envmix-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e9402845fb06d4a02b434e393fb7e18b0995dc8f47d613a01cc4a9ba5c3383a4
MD5 a22c8c91dac3842ed75e85f4c3e0df8d
BLAKE2b-256 e8614ded333aa7ad990ad30de52a6d45b6b1d0c59968212483633c0a1d5f53cb

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