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.

This package uses uv for project management. To get started, ensure that uv is installed on your machine and updated to the 0.5.6 version. Detailed installation instructions for uv can be found here.

Installation

uv add 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 pyamldantic import YAMLConfig
from pydantic import BaseModel, SecretStr

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...")
    ...

Development

uv sync --group=development
uv run pre-commit install --install-hooks
uv run pre-commit install --hook-type=commit-msg

Testing

uv sync --group=testing
uv run pytest

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.2.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

pyamldantic-1.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyamldantic-1.2.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.5.6

File hashes

Hashes for pyamldantic-1.2.0.tar.gz
Algorithm Hash digest
SHA256 d85b8f9fb7be3d25b19fedc47099d88ac10f2cd1dd7595a1d80b7b731331ebd9
MD5 5ef2c7f601c79e02ecd793b9bf51d6fe
BLAKE2b-256 58e4999c2b271cdbb086422e5d114066bcc41abdbe003b8f6d092fc496138920

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyamldantic-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2851795887f401cd407dde86b68a3934d0069a7ae002f9a7515c789468ecd290
MD5 957e3ed72391bada6cb62c79256d6eff
BLAKE2b-256 4ad35729224bd8940b0465eee2432f78001d5070d60ec2ffe15ee4e3b5be9e65

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