Skip to main content

Convert YAML configuration files to Python objects

Project description

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

License: MIT

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 is True, pyya will raise error if section name is not valid Python identifier.

Contributing

Are you a developer?

  • Fork the repository
  • 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.0.tar.gz (4.4 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.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyya-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a88c9ed03abb126e970048de982e57e2c928b32be10c0183a708d6e579bf9c53
MD5 5f2fbdbf83b6e73f31ed0c30804c471d
BLAKE2b-256 eb6de983bf86816d1f492d8683e8b0c9ed124235586e0f20dd5e7e868d6b4c4b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pyya-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0b50b19e91c1e0b1d6b184fe97d9088f3292deb8695268664495c403c702b730
MD5 bb3fb46fbd3307106fec26ffdef8d22a
BLAKE2b-256 b3d824bde66a467f604a92330c81356e1498fe8926f002d562d8c0750429fdc7

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