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]

    # 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

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

Uploaded Source

Built Distribution

configuraptor-1.11.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for configuraptor-1.11.0.tar.gz
Algorithm Hash digest
SHA256 5d6c0f4f82216d132ec2dde743f1de60f105363762e4baebe2f8d3aa56e29ec2
MD5 7bbc3f8457492ec469ddb3c8741aabd6
BLAKE2b-256 a6a4bba5e3af46a15a9d58886490bec640cb45ce8b9901725147963f38982b9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for configuraptor-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b8fd68cc93c5b737983cb8360211d2422f349e36fab0f4908426397d6c244d
MD5 2624e51e541202f0b1ee2a998c96642d
BLAKE2b-256 5e3952d731a6885685411da05c998bfc31ecb8d0a9ee217da89c2b36ca98afa7

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