All Projects → altescy → colt

altescy / colt

Licence: MIT License
A configuration utility for Python objects inspired by AllenNLP.

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to colt

harg
Haskell program configuration using higher kinded data
Stars: ✭ 23 (+35.29%)
Mutual labels:  configuration
puppet-augeasproviders
Alternative Augeas-based providers for Puppet
Stars: ✭ 64 (+276.47%)
Mutual labels:  configuration
env
A lightweight package for loading OS environment variables into structs for Go projects
Stars: ✭ 24 (+41.18%)
Mutual labels:  configuration
ienv
Improved shell environment: sane dotfiles backed by my daily work optimized for solarized theme
Stars: ✭ 25 (+47.06%)
Mutual labels:  configuration
config
Configure your application in PHP, with PSR-11 implementation
Stars: ✭ 19 (+11.76%)
Mutual labels:  configuration
flagga
An extensible Go library for handling program configuration using flags.
Stars: ✭ 28 (+64.71%)
Mutual labels:  configuration
yaask
Make your yaml configurable with interactive configurations!
Stars: ✭ 15 (-11.76%)
Mutual labels:  configuration
ZConfer
The ultimate ZSH configuration utility.
Stars: ✭ 26 (+52.94%)
Mutual labels:  configuration
MEMCM-OSD-Scripts
OSD Scripts
Stars: ✭ 34 (+100%)
Mutual labels:  configuration
killer-storybook-config
A killer Storybook Webpack config to help you bootstrap a great storybook config ASAP. It includes a React Frontend, GraphQL compatibility for Storybook, TypeScript, Babel, and ESlint.
Stars: ✭ 32 (+88.24%)
Mutual labels:  configuration
Flutter-Global-Config
A flutter package for managing different configurations and making them available everythere inside the app.
Stars: ✭ 88 (+417.65%)
Mutual labels:  configuration
jekyll-deploy-action
🪂 A Github Action to deploy the Jekyll site conveniently for GitHub Pages.
Stars: ✭ 162 (+852.94%)
Mutual labels:  configuration
sccm
Microsoft System Center Configuration Manager
Stars: ✭ 21 (+23.53%)
Mutual labels:  configuration
dhall-scala
dhall-scala is a Scala library for consuming dhall configuration files from Scala programming language.
Stars: ✭ 39 (+129.41%)
Mutual labels:  configuration
easy-props
The simple, stupid properties library for Java
Stars: ✭ 76 (+347.06%)
Mutual labels:  configuration
config-o-matic
🍷 Configure Slackware installs in no time with config-o-matic!
Stars: ✭ 16 (-5.88%)
Mutual labels:  configuration
config-parser
A slim, fully managed C# library for reading/writing .ini, .conf, .cfg etc configuration files.
Stars: ✭ 67 (+294.12%)
Mutual labels:  configuration
org-starter
Configure files and directories in Org mode more easily
Stars: ✭ 73 (+329.41%)
Mutual labels:  configuration
road-to-orleans
This repository illustrates the road to orleans with practical, real-life examples. From most basic, to more advanced techniques.
Stars: ✭ 55 (+223.53%)
Mutual labels:  configuration
gconfigs
gConfigs - Config and Secret parser
Stars: ✭ 42 (+147.06%)
Mutual labels:  configuration

colt

CI Actions Status Pulish Actions Status Python version pypi version license

Quick Links

Introduction

colt is a configuration utility for Python objects. colt constructs Python objects from a configuration dict which is convertable into JSON. (Inspired by AllenNLP)

Installation

pip install colt

Examples

Basic Usage

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"

scikit-learn Configuration

import colt

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

if __name__ == "__main__":
    config = {
        # import types automatically if type name is not registerd
        "@type": "sklearn.ensemble.VotingClassifier",
        "estimators": [
            ("rfc", { "@type": "sklearn.ensemble.RandomForestClassifier",
                      "n_estimators": 10 }),
            ("svc", { "@type": "sklearn.svm.SVC",
                      "gamma": "scale" }),
        ]
    }

    X, y = load_iris(return_X_y=True)
    X_train, X_valid, y_train, y_valid = train_test_split(X, y)

    model = colt.build(config)
    model.fit(X_train, y_train)

    valid_accuracy = model.score(X_valid, y_valid)
    print(f"valid_accuracy: {valid_accuracy}")

Registrable Class

By using the Registrable class, you can devide namespace into each class. In a following example, Foo and Bar have different namespaces.

import colt

class Foo(colt.Registrable):
    pass

class Bar(colt.Registrable):
    pass

@Foo.register("baz")
class FooBaz(Foo):
    pass

@Bar.register("baz")
class BarBaz(Bar):
    pass

@colt.register("my_class")
class MyClass:
    def __init__(self, foo: Foo, bar: Bar):
        self.foo = foo
        self.bar = bar

if __name__ == "__main__":
    config = {
        "@type": "my_class",
        "foo": {"@type": "baz"},
        "bar": {"@type": "baz"}
    }

    obj = colt.build(config)

    assert isinstance(obj.foo, FooBaz)
    assert isinstance(obj.bar, BarBaz)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].