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.5.0.tar.gz
(513.7 kB
view details)
Built Distribution
File details
Details for the file configuraptor-1.5.0.tar.gz
.
File metadata
- Download URL: configuraptor-1.5.0.tar.gz
- Upload date:
- Size: 513.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 962d76469ef1480648fdbf579e2b60956ba056cc4454f8ec1cff72696e8312f3 |
|
MD5 | ff0e6d447292e0fdce855959a0a05284 |
|
BLAKE2b-256 | bfc677673113b1028311d154c4d43124d53b6b68bb48f1815ceeecaee7db5604 |
File details
Details for the file configuraptor-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: configuraptor-1.5.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd103651d55d40a89aa760327a0e68e168a24eb03209818186815ca507b97f96 |
|
MD5 | df618ad97378773deddb1d8ecefb85ba |
|
BLAKE2b-256 | ece19190e8d6a330415b1e286ca69dfc484e5f91a97b5b95c96c1f4e35e30026 |