Skip to main content

Configuration parser based on YAML-Files with support for variables, overlaying and hierarchies

Project description

Build Status Documentation Status Version Downloads License (MIT) Supported Python versions

Configcrunch is a Python library written in Rust for reading YAML-based configuration files. It aims to be simple and fast while also providing some very powerful features.

Configcrunch is compatible with Python 3.6 and up.

Install it via pip: pip install configcrunch

Features:

  • Read configuration files from YAML files.

  • Define various types of configuration files, that can be validated via a schema.

  • Types of configuration files are defined as separate Python classes.

  • Documents can be configured to contain nested documents of any type.

  • Documents can contain Minijinja templates that can reference any other field inside the same or parent document.

  • The classes that represent your document types can contain methods that can be used inside the configuration files.

  • Documents can reference documents from other files. Configcrunch will merge them together. You decide where referenced documents are looked up.

  • Configuration objects can also be created without YAML files, by using ordinary Python dicts.

  • All features are optional.

Used by:

  • Riptide

  • (Your project here! Open an issue.)

By default Configcrunch uses schema to validate schemas. But you can also use your own validation logic!

Example

This is an example that uses most of the features described above, using two document types.

# doc1.yml - Type: one
one:
    name: Document
    number: 1
    sub:
        # Sub-document of type "two"
        $ref: /doc2
        two_field: "{{ parent().method() }}"
# <lookup path>/doc2.yml - Type: two
two:
    name: Doc 2
    number: 2
    two_field: This is overridden
# classes.py
from schema import Schema, Optional

from configcrunch import YamlConfigDocument, DocReference, variable_helper


class One(YamlConfigDocument):
    @classmethod
    def header(cls) -> str:
        return "one"

    @classmethod
    def schema(cls) -> Schema:
        return Schema(
            {
                Optional('$ref'): str,  # reference to other One documents
                'name': str,
                'number': int,
                Optional('sub'): DocReference(Two)
            }
        )

    @classmethod
    def subdocuments(cls):
        return [
            ("sub", Two)
        ]

    @variable_helper
    def method(self):
        return "I will return something"


class Two(YamlConfigDocument):
    @classmethod
    def header(cls) -> str:
        return "two"

    @classmethod
    def schema(cls) -> Schema:
        return Schema(
            {
                Optional('$ref'): str,  # reference to other Two documents
                'name': str,
                'number': int,
                'two_field': str
            }
        )

    @classmethod
    def subdocuments(cls):
        return []

The document “one.yml” can then be read via Python:

>>> import yaml
>>> from classes import One
>>> doc = One.from_yaml('./doc1.yml')
>>> doc.resolve_and_merge_references(['<lookup path>'])
>>> doc.process_vars()
>>> print(yaml.dump(doc.to_dict(), default_flow_style=False))
one:
  name: Document
  number: 1
  sub:
    name: Doc 2
    number: 2
    two_field: I will return something

Tests

Inside the configcrunch.tests package are tests.

To run the tests, see run_tests.sh.

Documentation

The complete documentation can be found at Read the Docs (or in the docs directory).

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

configcrunch-1.0.2-cp310-cp310-win_amd64.whl (609.5 kB view details)

Uploaded CPython 3.10Windows x86-64

configcrunch-1.0.2-cp310-cp310-win32.whl (577.0 kB view details)

Uploaded CPython 3.10Windows x86

configcrunch-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

configcrunch-1.0.2-cp310-cp310-macosx_11_0_x86_64.whl (747.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ x86-64

configcrunch-1.0.2-cp39-cp39-win_amd64.whl (609.6 kB view details)

Uploaded CPython 3.9Windows x86-64

configcrunch-1.0.2-cp39-cp39-win32.whl (577.1 kB view details)

Uploaded CPython 3.9Windows x86

configcrunch-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

configcrunch-1.0.2-cp39-cp39-macosx_11_0_x86_64.whl (748.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ x86-64

configcrunch-1.0.2-cp38-cp38-win_amd64.whl (609.0 kB view details)

Uploaded CPython 3.8Windows x86-64

configcrunch-1.0.2-cp38-cp38-win32.whl (576.3 kB view details)

Uploaded CPython 3.8Windows x86

configcrunch-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

configcrunch-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl (746.3 kB view details)

Uploaded CPython 3.8macOS 11.0+ x86-64

configcrunch-1.0.2-cp37-cp37m-win_amd64.whl (608.8 kB view details)

Uploaded CPython 3.7mWindows x86-64

configcrunch-1.0.2-cp37-cp37m-win32.whl (576.4 kB view details)

Uploaded CPython 3.7mWindows x86

configcrunch-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64manylinux: glibc 2.5+ x86-64

configcrunch-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl (746.0 kB view details)

Uploaded CPython 3.7mmacOS 11.0+ x86-64

File details

Details for the file configcrunch-1.0.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 48111b53cdf5eb67a2304fbb11b4f34e2fa07ff23642669645e42e292bce0308
MD5 7a77021ee8de53ccfb865eac061fa77c
BLAKE2b-256 0d2365fa382a1397013b9826ac78b0a9f7f9b4b499a6d9357734d5d849408c37

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp310-cp310-win32.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp310-cp310-win32.whl
  • Upload date:
  • Size: 577.0 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 49a0b0e164718a032ca4bb80a2c55bdf2de9ae99e00f3eb9fc6a4fc5dd2513d1
MD5 7422fd0fb01a51ab309701caad0fc076
BLAKE2b-256 47e230bf16b54ae252a8d8f86cc5d5be0c7688193da70ec29247dfb3fcbfd29d

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3c7d5f3dfe6df2c283cb25e051c0cb4d720b3f44e2de37923b1754683ab273ce
MD5 629b876e30c38395c87c42cd972274ea
BLAKE2b-256 05b40e6b0bd7ae8b21eb4f03cad2cefae59b4ab13ebfe37377464dcb0357946d

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 063f308eade602282c98be8058c03bb1d3f411d7d7f2f5ede13275f789050fe3
MD5 5b7a7523a964e99a469c8c0d5b282aff
BLAKE2b-256 429779f15808defb7dad648a56105862a7cba82c56ae3439878a33c5ef5b7298

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 609.6 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 45228020382cf14bca4372cdae83c14c7c63b22e611a7dca287ec025122bbe35
MD5 2f4caf6bc7bfb6acb725145bf03ee235
BLAKE2b-256 a4bb20bf6f027a121fac232831ea420d46e51e4c10089afab98e73bf6394cdee

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp39-cp39-win32.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp39-cp39-win32.whl
  • Upload date:
  • Size: 577.1 kB
  • Tags: CPython 3.9, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp39-cp39-win32.whl
Algorithm Hash digest
SHA256 985110d11ccd94fa50f93cfe675a6b56cde9e338577ff20af15050c9c5bec7ad
MD5 f02306b942789ca758dbb0adf17dcaf8
BLAKE2b-256 4b1bb1e9fded9a402d8cf1ee47c9227d6e119b7d1a4208d1a36b1821d147296b

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e5717c93a62a7d77fc4370beb48bea88862b6e49610d064bb41afe9b656bff42
MD5 a3bd72431becd9d91596a62275c18e42
BLAKE2b-256 8163a3c196bd1ced9ad6fa2c6bdab594caa9b98b073cd8210f55fe6a4bc07d9a

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 e7e7648cc805a7420ca33222edb2616a1674467a8e34ed7ea39bb42fccbb3b7b
MD5 0629573f1d8ca8a3c04bc6caf8d67f3c
BLAKE2b-256 d780e357d971571caf4017940ea1523cc6da0be7779bfbb85ae73f91d70f0ef7

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 609.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5f8ca94b5473e50add5d41077d414e05f79d91ed426d27f6dde253babb9f83f1
MD5 133fd6f97a66b566cd9865c600e5ea1b
BLAKE2b-256 74442524db74538d0e8ef9b52a80cc19d043db52c3aee7624efbfc39598d8c2b

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp38-cp38-win32.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp38-cp38-win32.whl
  • Upload date:
  • Size: 576.3 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 f85f406b67e3da703bcb46e79e3567cf5735a88d7ef391e8868a407e9768a267
MD5 c9349ac0e1ce6831f308bc2139dc44c4
BLAKE2b-256 84d15d14f19efd43deed89f134f292e2edc2a3b9d82bc935324a5247f0842803

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5d97f9751f55411d6b1b76e27566c38ca7105f1b80ffb8812d285252e168e486
MD5 e25900389da39abf5e0b126445093763
BLAKE2b-256 57e7ad8ea475d66d63e558fd7c6c794ab17a1f6157bee9e04c0893346f2160c1

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp38-cp38-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 5307f1adef172d81a7bf663da98e7497ad4fac43b87b49e8a384cf0273e6a3dc
MD5 df376e6bcbafa8875840676169a5a7c0
BLAKE2b-256 0bae20f971d8011375e128d348e581b7e77385318a568b73cf5a12bed6394c8b

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp37-cp37m-win_amd64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 10a0025d0687a09ea465285b85b9128dcbf11e535516ec55a05736ad62791fa6
MD5 98a01b06e2335165f57756c09532f615
BLAKE2b-256 c79b87f73fab21cd564abad15d0d7030e1749d7b801a4b57ece80503a1ce4dc0

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp37-cp37m-win32.whl.

File metadata

  • Download URL: configcrunch-1.0.2-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 576.4 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.13

File hashes

Hashes for configcrunch-1.0.2-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 4a4d49e8ab466ce718189c32cda23bbada6525918312575ac2314f1416d55748
MD5 449e47588504a7e3de0268d30d70e2ff
BLAKE2b-256 0fea2ecc486b92942472b13adb96603b0e8313d2559af52a4ed2820e1884bae9

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5c8eb56bfe0c513484b8e5f4aa31c2acce45b630b656cba98ae88e9760f1e9b4
MD5 752c02aff59a45e584b51c87d4f6762f
BLAKE2b-256 b82846a49a4833d39a52ac76e45bf918153c3670f1f36ccfdfa2e21bd50b1bb7

See more details on using hashes here.

File details

Details for the file configcrunch-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for configcrunch-1.0.2-cp37-cp37m-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 15fe5bc824b7fd17e0915eb8cae2e88511918bfcd58438e7241455b3e3554c30
MD5 265f29a83dd734d65b4fd61ef7e386fe
BLAKE2b-256 238941d72d9958b6d77cd2a1efe1d41122ba0527f514d5f0b67557c8cfef5629

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