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.
# examples/example_from_readme.toml
[config]
name = "Hello World!"
[config.reference]
number = 42
numbers = [41, 43]
string = "42"
Could be loaded into Python classes using the following code:
# examples/example_from_readme.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_readme.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_readme.toml") # or .json, .yaml
print(my_config.name)
# Hello World!
print(my_config.reference.numbers)
# [41, 43]
More examples can be round in examples.
License
configuraptor
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.3.2.tar.gz
(508.9 kB
view hashes)
Built Distribution
Close
Hashes for configuraptor-1.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b4a7ceaafd6a224e57f3ec4120b590100a65b0b920f2133b28559bba006cefa |
|
MD5 | 02fb55b5351e9711fa4004c98557d52d |
|
BLAKE2b-256 | 1f2be3f26b117d51c0e0ee31cabf8e1d5d8d96dc727e4e93499b206dae97e53b |