Convert YAML configuration files to Python objects
Project description
pyya - Simple tool that converts YAML configuration files to Python objects
Features
- Very
lightweightandsimpleAPI (currently it contains only one function) Easyto use- Based on popular and well-tested libraries (like
camel-converter,PyYAMLandmunch) - Automatically
mergedefault 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',
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.
and can be configured to .
Flags
convert_keys_to_snake_case=True
# `pyya` converts `camelCase` or `PascalCase` keys to `snake_case`
add_underscore_prefix_to_keywords=True
# `pyya` adds underscore prefix to keys that are Python keywords
raise_error_non_identifiers=True
# `pyya` raises error if key 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyya-0.1.3.tar.gz.
File metadata
- Download URL: pyya-0.1.3.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f0b268efea2e0413b3b8a1b93758a7a3abdfa4b476919ab259f6ed4efff8b6e
|
|
| MD5 |
6eb05e2487b5faf879e13d33e3ca6369
|
|
| BLAKE2b-256 |
fac10f7ec6ade6a613762769c64cc97b6a33a355d53d99a2e5de868189a290b2
|
File details
Details for the file pyya-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pyya-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0392d5c7f29f13f2d66e078dc88556e25a87f3b97ba3b491a37d9e3fdbe23223
|
|
| MD5 |
5e7df2c7fa0bfc59a4f2fbc39d984eaa
|
|
| BLAKE2b-256 |
e582ffb1276ffcade7d179306b23dfb8e040b078842ee782d280cc5c904a17ce
|