Load toml/yaml/json config files into classes for a typed config (type hinting etc.)
Project description
Configuraptor
Load toml/yaml/json config files into classes for a typed config (type hinting etc.).
Table of Contents
Installation
pip install configuraptor
Usage
Configuraptor can be used to load your config files into structured Python classes.
# example_from_docs.toml
[config]
name = "Hello World!"
[config.reference]
number = 42
numbers = [41, 43]
string = "42"
Could be loaded into Python classes using the following code:
# example_from_docs.py
from configuraptor import load_into, TypedConfig
######################
# with basic classes #
######################
class SomeRegularClass:
number: int
numbers: list[int]
string: str
class Config:
name: str
reference: SomeRegularClass
if __name__ == '__main__':
my_config = load_into(Config, "example_from_docs.toml") # or .json, .yaml
print(my_config.name)
# Hello World!
print(my_config.reference.numbers)
# [41, 43]
########################
# alternative notation #
########################
class SomeOtherRegularClass:
number: int
numbers: list[int]
string: str
class OtherConfig(TypedConfig):
name: str
reference: SomeRegularClass
if __name__ == '__main__':
my_config = OtherConfig.load("example_from_docs.toml") # or .json, .yaml
print(my_config.name)
# Hello World!
print(my_config.reference.numbers)
# [41, 43]
More examples will be available soon.
License
edwh
is distributed under the terms of the MIT license.
Changelog
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
configuraptor-1.1.0.tar.gz
(504.5 kB
view details)
Built Distribution
File details
Details for the file configuraptor-1.1.0.tar.gz
.
File metadata
- Download URL: configuraptor-1.1.0.tar.gz
- Upload date:
- Size: 504.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10df390bb9cd4b0099f34e3215b903e2b5fca171449b741732b985bbda52e982 |
|
MD5 | 29573e01df517fb49a2ecce3c452d47d |
|
BLAKE2b-256 | e4ea8bc5a4dbbbcf2011b1da03919fdb29172db349ab109f87052633a4b30441 |
File details
Details for the file configuraptor-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: configuraptor-1.1.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53b350e2f29fd8429009b6f99eb8b9f0f168ae274e735a701eff9e968a5e8aeb |
|
MD5 | afc1ffe36b45bffbfd3ebbc530013598 |
|
BLAKE2b-256 | d1aa37aa541113aa4a29a46f7912b579d338b891967f01918d47ee91cd56810e |