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 --frozen --group=development
uv run --frozen pre-commit install --install-hooks
uv run --frozen pre-commit install --hook-type=commit-msg

Testing

uv sync --frozen --group=testing
uv run --frozen 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.3.0.tar.gz (21.4 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.3.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyamldantic-1.3.0.tar.gz
Algorithm Hash digest
SHA256 e0660ae6c6b5588e64c531e506d0263913ceadb4041f7d15e3cc0a24c0478ad5
MD5 01a69d013a2e0f284ffac77d63458159
BLAKE2b-256 8e78eca40841a9c35343c85de6bdbed0f74c96b50e124b54a6bdb8f21e3e9ce3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyamldantic-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ca23b8a507d62dbc003b020305d518a0f42bf6d086f97825b547dfdb5cb559
MD5 99f043b0669af5a41d4035b62e9af29b
BLAKE2b-256 01d45e89e251d86e8bb7c8fdabd65005429c08e4a44a399332b3e8824350470d

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