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

Uploaded Source

Built Distribution

configuraptor-1.10.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for configuraptor-1.10.0.tar.gz
Algorithm Hash digest
SHA256 91d8c2dfce3adc09b1863c68d075704b6144d88ccb8df1c060bda3e8c6e0d309
MD5 51d6ac92789b328399f331302c91d440
BLAKE2b-256 389141f5c33f528dc15a788be5a77faa9e1c435c7f27dc9eb28ca4310285eba0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for configuraptor-1.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d2e32dc4512b71b3524f514e6541b8fbd50987585d3bd935a4d1e28cfcd64ad9
MD5 b5c3798b99d08420dcd0cbad3b612df3
BLAKE2b-256 5a3ace7f3700a3854f745b3374515f94d2cf833ffcfbfb666c3c4a2c9b35b648

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