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.

# 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

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

Uploaded Source

Built Distribution

configuraptor-1.1.2-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for configuraptor-1.1.2.tar.gz
Algorithm Hash digest
SHA256 40789e562a9dabe900241b3d29f3da6e4cbf9fb608eb235c487564dc512c0375
MD5 a6c4806f46d9a398390fa668438435d6
BLAKE2b-256 e911b83e5ca35c038a5a5e6edc8d6c1d6f798a830003118efacc076ab48d2d93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for configuraptor-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 28074441fc4ade4f00e16a2ad571f052a9bee77b384afb54a71635ae3ac35292
MD5 7a852c19f78c5b34c7b637325946a7f4
BLAKE2b-256 6af63f5c387b9f6d7235235222467c37768fda9e63e9c7642158ecf6be0f042c

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