Skip to main content

Load toml/yaml/json config files into classes for a typed config (type hinting etc.)

Project description

Classy Configuraptor

Configuraptor

Load toml/yaml/json config files into classes for a typed config (type hinting etc.).

PyPI - Version PyPI - Python Version
Code style: black License: MIT
su6 checks Coverage

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

See CHANGELOG.md

Project details


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.4.0.tar.gz (510.0 kB view details)

Uploaded Source

Built Distribution

configuraptor-1.4.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file configuraptor-1.4.0.tar.gz.

File metadata

  • Download URL: configuraptor-1.4.0.tar.gz
  • Upload date:
  • Size: 510.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.24.1

File hashes

Hashes for configuraptor-1.4.0.tar.gz
Algorithm Hash digest
SHA256 0e4c8303e53c8eb1a8d3500fd5f9797bdb3087ff9c8695e9691cc15fa4456d48
MD5 ff1fd2d08244f80dcc2286e36ec62784
BLAKE2b-256 6838c054500e11ce9b786d3e7045c16cb8c44cac199989f48fdaf8a178da51a8

See more details on using hashes here.

File details

Details for the file configuraptor-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for configuraptor-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0da11ee6b361e9ba95e66d238b164990f741866c61415da21f63d58c69fdeb0d
MD5 925155445abea2fbf0fd12a1368fdeba
BLAKE2b-256 a03ae612d4ca66cb89671722f8e6ea04a5a7fb55a94aa99a09ce96ce10c749a2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page