Skip to main content

Convert YAML configuration files to Python objects

Project description

paya - Simple tool that converts YAML configuration files to Python objects

PyPI - Downloads ClickPy Dashboard 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 camel-converter and munch)
  • Automatically merge default and production configuration files
  • Convert keys in configuration files to snake_case

Installation

pip install pyya

Usage

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
# config.yaml - this file for production usage
database:   
    username: username
    password: password

Import configuration files in your Python code with pyya:

import json

from pyya import init_config

config = init_config(
    'config.yaml', 'default.config.yaml', 
    convert_keys_to_snake_case = False,
    raise_error_non_identifiers = False)
print(json.dumps(config.database))

# Output:
# {"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 munch library to create attribute-stylish dictionaries.

paya automatically adds underscore prefix to Python keywords and can be configured to convert camelCase or PascalCase keys to snake_case.

If raise_error_non_identifiers=True, pyya will raise error if section name is not valid Python identifier.

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

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

pyya-0.1.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

pyya-0.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file pyya-0.1.1.tar.gz.

File metadata

  • Download URL: pyya-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for pyya-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9c602b870f6333b1488778df3867f4395a26cf4ede4e2c10ae3ef0b21081ef1e
MD5 94ea06d26a333f3649f2b344822d5908
BLAKE2b-256 fc4d89fc1a58ec8beb0768c6cd4a620cfec3a9964647760e1814d98072076752

See more details on using hashes here.

File details

Details for the file pyya-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyya-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.7

File hashes

Hashes for pyya-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 48985ccd78f08a987410a24d92edf9be05c6f38c7aaf65d2a0f5d450703b4847
MD5 031ac6413feed31a06e573889f9628cf
BLAKE2b-256 c2b542b690d54cdc2cff4d294e09e198e569988092e786217afa99ecbaaf9dad

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