Skip to main content

pyya - Simple tool that converts YAML/TOML configuration files to Python objects

PyPI - Downloads ClickPy Dashboard GitHub Downloads (all assets, all releases) PyPI - Python Version PyPI - Link PyPI - Version PyPI - Wheel License: MIT

Features

  • Very lightweight and simple API (currently it contains only one function)
  • Easy to use
  • Based on popular and well-tested libraries (like pydantic, camel-converter, PyYAML, toml and munch)
  • Automatically merge default and production configuration files
  • Convert keys in configuration files to snake_case
  • YAML/TOML validation with Pydantic models
  • Generate stub files for your dynamic configuration with pyya CLI tool.

Installation

pip install pyya

Or download a specific version from Releases page and install it with:

pip install /path/to/pyya-[version]-py3-none-any.whl

Usage

Example

Create YAML configuration files for your project:

# default.config.yaml - this file usually goes to version control system
database:
  host: localhost
  port: 5432
  username: postgres
  password: postgres

redis:
  host: localhost
  port: 6379
# config.yaml - this file for production usage
database:
  username: username
  password: password
  name: db

Import configuration files in your Python code with pyya:

# config.py
import json

from pyya import init_config, logger

logger.setLevel(logging.INFO)

config = init_config(
    'config.yaml', 'default.config.yaml',
    convert_keys_to_snake_case = False,
    add_underscore_prefix_to_keywords = False,
    raise_error_non_identifiers = False,
    replace_dashes_with_underscores = False,
    merge_configs = True,
    sections_ignored_on_merge = ['redis'], # do not include redis in your config
    validate_data_types = True,
    allow_extra_sections = True,
    warn_extra_sections = True,
    )
print(json.dumps(config))

# Output:
# 2025-09-05 09:13:17,280         WARNING         pyya            The following extra sections will be ignored:
# {'database.name': 'db'}
# 2025-09-05 09:13:17,281         INFO            pyya            The following sections were overwritten:
# {database: {'host': 'localhost', 'port': 5432}}
# {database: {"host": "localhost", "port": 5432, "username": "username", "password": "password"}}

As you can see, pyya automatically merges default config file with production config file.

Under the hood pyya uses PyYAML to parse YAML files and munch library to create attribute-stylish dictionaries.

For TOML files the logic is the same except you should point pyya to correct TOML files (e.g. config.toml)

Flags

# convert `camelCase` or `PascalCase` keys to `snake_case`
convert_keys_to_snake_case=False
# add underscore prefix to keys that are Python keywords
add_underscore_prefix_to_keywords=False
# raise error if key name is not valid Python identifier
raise_error_non_identifiers=False
# replace dashes with underscores in section names and keys
replace_dashes_with_underscores=False
# merge default and production configuration files
# setting to `False` disables below flags and makes default config optional
# `False` means "open config file and apply `yaml.safe_load` and `munchify` with specified formatting"
merge_configs=True
# list of sections to ignore when merging configs
# it is useful when you have examples in your default config but do not want to have in the main one
sections_ignored_on_merge=None
# raise error if data types in production config are not the same as default
# validation based on data types inferred from default config
validate_data_types=True
# raise error on any extra sections in production config
allow_extra_sections=True
# if extra sections are allowed, warn about extra keys and values
warn_extra_sections=True

By default autocompletion does not work with attribute-style configurations generated by pyya. However, you can generate special stub files with .pyi extension to make you LSP or mypy to properly suggest configuration fields.

With pyya it actually very straightforward (assuming you have config.py file like in the example above):

# pyya is a CLI tool installed automatically when you run pip install
pyya --input "default.config.yaml" --output "config.pyi"

This will create a special file with type hints for config.py file (note that both files should have the same basename).

Contributing

Are you a developer?

  • Fork the repository https://github.com/shadowy-pycoder/pyya/fork
  • Clone the repository: git clone https://github.com/<your-username>/pyya.git && cd pyya
  • Create your feature branch: git switch -c my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request

Metadata

Release files for pyya 0.1.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyya 0.1.15
File Size Uploaded
pyya-0.1.15.tar.gz 12.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyya 0.1.15
File Interpreter ABI Platform
pyya-0.1.15-py3-none-any.whl Python 3 none any Details

Total release size: 20.6 kB

Release files / pyya-0.1.15.tar.gz

Download URL pyya-0.1.15.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6d1536dbd54276c9149a350c06251ed64d367d0d9668184f1d05751c132921bc
BLAKE2b-256 checksum
How to use checksums
008b9db4fbeced1e5690e0bbd3531827fb335b5b317510bedb94a8f972d0aa9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release files / pyya-0.1.15-py3-none-any.whl

Download URL pyya-0.1.15-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b2024a3b3d2302d61704de1ea525d3ce34d2794c92a4c725cf64bb9ad7ba15e
BLAKE2b-256 checksum
How to use checksums
312288d431adbabddf33c5388b79232a354ff0dc810ffc9891961840bdad40b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.14

Release history Release notifications | RSS feed

This release

0.1.15 This release

2 release files

0.1.13

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page