Skip to main content

Better configs with TOML support

Project description

Confboy

Better configs with TOML support.

Installation

Use the package manager pip to install confboy.

pip install confboy

Usage

import confboy


base_config = {
    'nested': {
        'one': 1,
        'two': 2,
    },
    'three': 3,
}

config = confboy.Config(base_config)

config.nested.one  # Returns `1`
config.three       # Returns `3`

Although it is advised not to change the config during runtime, it is also possible:

config.nested.one = 10
config.nested.one  # Returns `10`

config.new_nested = {'one': 1}
config.new_nested.one  # Returns `10`

Confboy also supports dynamic values that can use other values from the same config. You can use it to build connection URLs or whatever. Shines with changing config during runtime: change config.postgres.user and config.postgres.url will be rebuilt on every query if it's a callable. You can do various things with it including mapping and filtering values the app got from the TOML config, cast types, whatever comes to your mind. Callables work on any nested level.

config = confboy.Config({
    'a': {'a': 1},
    'b': 2,
    'a_plus_b': 'callable:add',  # Tell confboy to call `add` from provided callables
})


def add():
    return config.a.a + config.b


config.register_callable(add)
config.a_plus_b  # Returns 3

Confboy can take values from TOML files as well. Provided config will be merged over base config.

# config.toml

[nested]
one = 1
two = 2

not = "nested"
config = confboy.Config(toml_config_path='config.toml')
config.nested.one  # Returns 1
config.not         # Returns 'nested'

Confboy's merges are soft: if the value is present in the config but not in patch, it won't be deleted from the config. It supports value deletion and everything. Just try it out or check the source code!

Async functions as callables

Currently confboy does not support asynchronous functions as callables. That would bring interface inconsistency like await config.foo vs config.foo. You can wrap your asynchronous function like that:

config.register_callable(
    functools.partial(asyncio.run, async_func()))

Although that'd block the event loop.

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

confboy1-1.1.2.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

confboy1-1.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file confboy1-1.1.2.tar.gz.

File metadata

  • Download URL: confboy1-1.1.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for confboy1-1.1.2.tar.gz
Algorithm Hash digest
SHA256 4f1d2468d1ce777682b25fa6b51675496481ef89bad06412aebe46ada9eea77e
MD5 b273d3e53b4ae3c89e50ec5f8883e33d
BLAKE2b-256 10bc30f7143061006e76ef68881a5e9b84bceb6a3c8e3eb5ada35cfe6dece3ae

See more details on using hashes here.

File details

Details for the file confboy1-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: confboy1-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for confboy1-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed82e2495309cb3c59e5f2a4b9bbdeb896ee26aaf198baccaa51952f018c31ec
MD5 8eb372aa0ccefa139a55a9ec22f3c1c5
BLAKE2b-256 17e74164286ea5103940f686404d8fb551cbf2fd26bf555369f491c7dd470687

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