|
| 1 | +Metadata-Version: 2.1 |
| 2 | +Name: pyya |
| 3 | +Version: 0.1.0 |
| 4 | +Summary: Convert YAML configuration files to Python objects |
| 5 | +Author-email: shadowy-pycoder < [email protected]> |
| 6 | +Project-URL: Homepage, https://github.com/shadowy-pycoder/pyya |
| 7 | +Project-URL: Repository, https://github.com/shadowy-pycoder/pyya |
| 8 | +Project-URL: Issues, https://github.com/shadowy-pycoder/pyya/issues |
| 9 | +Classifier: Programming Language :: Python :: 3 |
| 10 | +Classifier: Programming Language :: Python :: 3.8 |
| 11 | +Classifier: Programming Language :: Python :: 3.9 |
| 12 | +Classifier: Programming Language :: Python :: 3.10 |
| 13 | +Classifier: Programming Language :: Python :: 3.11 |
| 14 | +Classifier: Programming Language :: Python :: 3.12 |
| 15 | +Classifier: Programming Language :: Python :: 3.13 |
| 16 | +Classifier: License :: OSI Approved :: MIT License |
| 17 | +Classifier: Operating System :: MacOS :: MacOS X |
| 18 | +Classifier: Operating System :: Microsoft :: Windows |
| 19 | +Classifier: Operating System :: POSIX :: Linux |
| 20 | +Requires-Python: >=3.8 |
| 21 | +Description-Content-Type: text/markdown |
| 22 | +Requires-Dist: camel-converter>=3.1.2 |
| 23 | +Requires-Dist: munch>=4.0.0 |
| 24 | +Requires-Dist: pyyaml>=6.0.2 |
| 25 | +Requires-Dist: types-pyyaml>=6.0.12.20240917 |
| 26 | + |
| 27 | +# paya - Simple tool that converts YAML configuration files to Python objects |
| 28 | + |
| 29 | +[](https://opensource.org/licenses/MIT) |
| 30 | + |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +```shell |
| 35 | +pip install pyya |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +Create YAML configuration files for your project: |
| 41 | + |
| 42 | + |
| 43 | +```yaml |
| 44 | +# default.config.yaml - this file usually goes to version control system |
| 45 | +database: |
| 46 | + host: localhost |
| 47 | + port: 5432 |
| 48 | + username: postgres |
| 49 | + password: postgres |
| 50 | +``` |
| 51 | + |
| 52 | +```yaml |
| 53 | +# config.yaml - this file for production usage |
| 54 | +database: |
| 55 | + username: username |
| 56 | + password: password |
| 57 | +``` |
| 58 | + |
| 59 | +Import configuration files in your Python code with pyya: |
| 60 | + |
| 61 | +```python |
| 62 | +import json |
| 63 | + |
| 64 | +from pyya import init_config |
| 65 | + |
| 66 | +config = init_config( |
| 67 | + 'config.yaml', 'default.config.yaml', |
| 68 | + convert_keys_to_snake_case = False, |
| 69 | + raise_error_non_identifiers = False) |
| 70 | +print(json.dumps(config.database)) |
| 71 | + |
| 72 | +# Output: |
| 73 | +# {"host": "localhost", "port": 5432, "username": "username", "password": "password"} |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +As you can see, pyya automatically merges default config file with production config file. |
| 78 | + |
| 79 | +Under the hood `pyya` uses [munch](https://pypi.org/project/munch/) library to create attribute-stylish dictionaries. |
| 80 | + |
| 81 | +`paya` automatically adds underscore prefix to Python keywords and can be configured to convert `camelCase` or `PascalCase` keys to snake_case. |
| 82 | + |
| 83 | +If `raise_error_non_identifiers` is True, `pyya` will raise error if section name is not valid Python identifier. |
| 84 | + |
| 85 | +## Contributing |
| 86 | + |
| 87 | +Are you a developer? |
| 88 | + |
| 89 | +- Fork the repository |
| 90 | +- Create your feature branch: `git switch -c my-new-feature` |
| 91 | +- Commit your changes: `git commit -am 'Add some feature'` |
| 92 | +- Push to the branch: `git push origin my-new-feature` |
| 93 | +- Submit a pull request |
0 commit comments