Skip to main content

Convert YAML configuration files to Python objects

Project description

pyya - 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, PyYAML and munch)
  • Automatically merge default and production configuration files
  • Convert keys in configuration files to snake_case

Installation

pip install pyya

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
# 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', 
    merge_configs = True,
    convert_keys_to_snake_case = False,
    add_underscore_prefix_to_keywords = 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 PyYAML to parse YAML files and munch library to create attribute-stylish dictionaries.

Flags

# merge default and production configuration files
# setting to `False` disables other flags and makes default config optional
# `False` means "open config file and apply `ymal.safe_load` and `munchify` with no formatting"
merge_configs=True 
# convert `camelCase` or `PascalCase` keys to `snake_case`
convert_keys_to_snake_case=True 
# add underscore prefix to keys that are Python keywords
add_underscore_prefix_to_keywords=True 
# raise error if key name is not valid Python identifier
raise_error_non_identifiers=True 

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.4.tar.gz (5.2 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.4-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyya-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f602263421a89ebd9e05597b6a7f42722c1c0b793ea5afb33b604d02f34bbadd
MD5 4759b49798caa0c8eb26dfb794d26296
BLAKE2b-256 6084f5f2a37f1cdcc99d17b5b5b5cb7900f6a4d9a75d45e1ac08da7507c93dd6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyya-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4ef374fe2b69a5448972a87c0996d7debfe0bd3052a20cdd4f228cc48b6c9ad0
MD5 18b1ec2c67d0ade07e83503096d8a9d5
BLAKE2b-256 4baeadf6c822b4020f40b785d8ea26ade840edd4b159f88869f5123c1d8762f4

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