Skip to main content

A configuration utility for Python object.

Project description

colt

Actions Status Python version pypi version license

Introduction

colt is a configuration utility for Python object. colt constructs Python object from configuration dict which is convertable into JSON.

Installation

pip install colt

Example

import typing as tp
import colt

@colt.register("foo")
class Foo:
    def __init__(self, message: str) -> None:
        self.message = message

@colt.register("bar")
class Bar:
    def __init__(self, foos: tp.List[Foo]) -> None:
        self.foos = foos

if __name__ == "__main__":
    config = {
        "@type": "bar",  # specify type-name with `@type`
        "foos": [
            {"message": "hello"},  # type of this is inferred from type-hint
            {"message": "world"},
        ]
    }

    bar = colt.build(config)

    assert isinstance(bar, Bar)

    print(" ".join(foo.message for foo in bar.foos))
        # => "hello world"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for colt, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size colt-0.2.0-py3-none-any.whl (5.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size colt-0.2.0.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page