Skip to main content

Validate and serialize YAML config files with Pydantic, with support for environment variables.

Project description

pyamldantic

Validate and serialize YAML config files with Pydantic, with support for environment variables.

Installation

pip install pyamldantic

Usage

config.yaml

database:
  host: $DATABASE_HOST
  name: $DATABASE_NAME
  password: $DATABASE_PASSWORD
  port: $DATABASE_PORT
  user: $DATABASE_USER
  timeout: $DATABASE_TIMEOUT?
environment: development
is-debug: true

config.py

from pydantic import BaseModel, SecretStr
from pyamldantic import YAMLConfig

class DatabaseSchema(BaseModel):
    host: str
    name: str
    password: SecretStr
    port: int
    user: str
    ssl: bool = False
    timeout: int | None = None

class Schema(BaseModel):
    database: DatabaseSchema
    environment: str
    is_debug: bool

config = YAMLConfig.load("config.yaml", schema=Schema)

main.py

from .config import config

if __name__ == "__main__":
    print(f"Initializing {config.environment} environment...")
    ...

Acknowledgments

This project was inspired by envyaml.

Contributing

Contributions are welcome! To get started, please refer to our contribution guidelines.

Issues

If you encounter any problems while using this package, please open a new issue here.

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

pyamldantic-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

pyamldantic-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file pyamldantic-1.0.0.tar.gz.

File metadata

  • Download URL: pyamldantic-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.6

File hashes

Hashes for pyamldantic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 16af1abb769f7db7aeaf3848c6c766d6f32928babcaee24d6b11c68273337f64
MD5 683b9e02a0f2d43dd652ec2c85f32e13
BLAKE2b-256 d3351564220315caf5a9bd92f71614abc7695d434e51d058b20c9224815176f9

See more details on using hashes here.

File details

Details for the file pyamldantic-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyamldantic-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.6

File hashes

Hashes for pyamldantic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c02e6463f34bea2ec140890a18e8625833b71056df5868a7b80054ab76715fce
MD5 e61f3b6b9fe5a3b7cb8d0147ee9aedae
BLAKE2b-256 6119e7285bca19dfafe3ea28f43e5f0d49688a835ebb2abcc0e172a1833dcf6a

See more details on using hashes here.

Supported by

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