Skip to main content

A static configuration parser for python using templates

Project description

TypeConf

A static configuration parser for python using templates

Python is as a dynamic programming language inherently prone to runtime errors. This is especially problematic for long-running programms. A wrong configuration then can lead to the loss of precious computation.

Sounds familiar?

TypeConf builds a configuration parser from templates, that can be hierarchical nested to define your individual configuration. This template can be easily parsed then at the beginning of your code and checked for your individual requirements.

Furthermore, TypeConf helps maintain up-to-date configurations by quickly revealing broken configurations and making easy to support old configurations despite changes.

Installation

From PyPi

pip install typeconf

From source

pip install git+https://github.com/kilsenp/TypeConf.git

Demo

# templates/parent.yaml
attr_int:
    dtype: int
    required: False
    help: "This is an int"
    default: 0
    type: "datatype"
attr_child:
    dtype: child
    required: False
    help: "This a type constructed from another yaml"
    type: "datatype"        
# templates/child.yaml
attr_bool:
    dtype: bool
    required: True
    help: "This is a bool"
    type: "datatype"

TypeConf will be automatically be able to solve the dependencies when building the type.

# main.py
from typeconf import TypeFactory
factory = TypeFactory()
factory.register_search_directory('templates')
template = factory.build_template('parent')

We can now pass a config file to be parsed.

# config.yaml
attr_child:
    attr_bool: True
template.fill_from_file('config.yaml')

This values can also be overwritten by command line arguments, addressing subconfigs through dot separated names.

from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('task')
# python main.py test attr_child.attr_bool=False
args, unknown_args = parser.parse_known_args()
# args.task = test
template.fill_from_cl(unknown_args)

Finally we create the config that can be used throughout the rest of the code.

config = template.to_config()  # Actual parsing happens here
# {
#    attr_int: 0,
#    attr_child: {
#       attr_bool: False  #overwritten by cli
#    }
# }

Features

  • Static configuration parsing before program is started
  • Easy verification of existing configurations, if they still work with the current pipeline
  • Easy extension of existing configurations by adding default values to templates
  • Automatically make types within a subfolder choosable
  • Comment individual configuration values
  • Overwrite values using the command line or from code
  • Data type testing, ensure the correct datatype:
    • int
    • float
    • str
    • bool

TODO

  • clean split between types, attributes, special types
  • Consistent naming
  • Allow more combinations e.g. choice of + datatype
  • better error messages
  • config from python file
  • unit tests
  • @config_file('path_to_cfg')
  • eval and type are not exclusive. make additional attribute
  • Better name parser instead of type?
  • Pretty print with comments
  • Command line interface
  • Conditional requirements. If a is set b also has to be set. Better if b is a part of a? Leads to duplicates
  • Generation of a seed.
  • Pip Package
  • Github Services
  • Copy From to ensure same training as validation, or make it as default?
  • ensure two values are equal, but then why even set two?
  • Config updates, pass multiple configs

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

typeconf-0.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typeconf-0.1-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file typeconf-0.1.tar.gz.

File metadata

  • Download URL: typeconf-0.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for typeconf-0.1.tar.gz
Algorithm Hash digest
SHA256 e9d5e7328102b6ccefdad6893166466c813fa37d496d46738d400e87b82043c5
MD5 f8a165d465106896ec0472cff3bf1bdb
BLAKE2b-256 fc4d32bc0c3b79a7edf9c05a53099d59bc23cc2bb5d6fbd0d7a60d0b837d708c

See more details on using hashes here.

File details

Details for the file typeconf-0.1-py3-none-any.whl.

File metadata

  • Download URL: typeconf-0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.3

File hashes

Hashes for typeconf-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39e165d0612afbb9218c63c873676d4971bb8fa82a808f6490930ab7fba756e2
MD5 c72e727baacf94eeb48eb8905fe183be
BLAKE2b-256 e803ee5e44e55235297b6f367f006b87698dd765902ccb83fa8e8a5c52f4742e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page