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
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.1.tar.gz
(506.5 kB
view details)
Built Distribution
File details
Details for the file configuraptor-1.3.1.tar.gz
.
File metadata
- Download URL: configuraptor-1.3.1.tar.gz
- Upload date:
- Size: 506.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a1561e2526ffcc3654776ecc08e7534c91888a537a465b998487e5fdcd7d920 |
|
MD5 | 2aec8c102f354fd6459d6b4feaacd8c4 |
|
BLAKE2b-256 | ffc54424d9190cfdcef538c2cd04f1504da4240cdf911c1bef3bcf38b7a0e158 |
File details
Details for the file configuraptor-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: configuraptor-1.3.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 182810494b2a672d1c1d50ecaf48a8285ab693a503006c2871af51cd678b306e |
|
MD5 | 617fa308db81ba5c740c399f4c49eab9 |
|
BLAKE2b-256 | 2996b63346a6ad2208099ad7d0d82cf46b5b0301c089280b37db8647b096c812 |