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]
# TypedConfig has an extra benefit of allowing .update:
my_config.update(numbers=[68, 70])
More examples can be found 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.7.1.tar.gz
(517.5 kB
view details)
Built Distribution
File details
Details for the file configuraptor-1.7.1.tar.gz
.
File metadata
- Download URL: configuraptor-1.7.1.tar.gz
- Upload date:
- Size: 517.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8f62872eeed1f229ce2ae12c51ad01b7c2c4aac1572a27f1ef5355f6b0896ce |
|
MD5 | 79576f8d56dd8f5152adc3fe8f087afd |
|
BLAKE2b-256 | f35c8a37c65510246df945c26dcc7d7caa9a3508ed5798351779e09bb276809d |
File details
Details for the file configuraptor-1.7.1-py3-none-any.whl
.
File metadata
- Download URL: configuraptor-1.7.1-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f197dcb26efeca04ab3487bc7241fee392bbb3b51613afa837f9be8e6afd2926 |
|
MD5 | 41443aad22215ab5e15e42748809aa9c |
|
BLAKE2b-256 | ac8d3234e4922ad8f45560b9f64fa2234e27fb12a3d022886aa56b806789ce53 |