Skip to main content

Lightweight self-healing config manager

Project description

ConfigLite

A lightweight self-healing config handler.

Quickstart

Subclass from the base BaseConfig object and add your variables and defaults.

You can then set import this from wherever is needed and access properties.

Installation

pypi

ConfigLite is available on pypi!

Simply run pip install configlite to install it in your current environment.

development

If you want to make changes to how configs are handled, you can clone this repo and run pip install -e . to install it in editable mode.

Usage

Creating a Config

There are two methods of creating a config object.

Direct Initialisation

The simplest method to create a config, simply init the BaseConfig class and provide your defaults as an argument:

from configlite import BaseConfig


CONFIG = BaseConfig(
    path = "config.yaml",
    defaults = {
        "value": 10,
        ...
    }
)

As a Class

If you wish to add extra methods, create a subclass of the base BaseConfig object, adding your parameters and their defaults to a defaults field.

For example:

from configlite import BaseConfig


class MyConfig(BaseConfig):
    defaults = {
        "value": 10,
        "name": "test",
        "pi": 3.14,
    }

You must still initialise the config, however:

CONFIG = MyConfig(path="config.yaml")

Access

To use your created config, there are two methods:

  • "globally", where a single instance created.
  • "locally", initialising the class where needed.

Global

To create a global config, set up the config as a parameter in the toplevel __init__.py:

CONFIG = MyConfig("./path/to/config.yaml")

Then in the rest of your code you may import this object:

from my_package import CONFIG

value = CONFIG.value

This is most useful if your code requires a single config file for everything.

Local

Or a local config, where you create an instance of your subclass wherever it is needed:

from my_package import MyConfig

config = MyConfig("./path/to/config.yaml")

value = config.value

This can be useful if you are juggling multiple different config files dynamically.

[!NOTE]

This method is only recommended for subclasses, as each instance requires the same arguments.

Paths

The BaseConfig object can take either a single path, or a list of paths.

If a list is passed, the config will search each one in order, using the last one in the list if none are found.

Path Lists

Lets say you create a config this way:

class Config(BaseConfig):
    ...

CONFIG = Config(
    paths=[
        "config.yaml",
        "~/.config/app/config.yaml",
    ]
)

In this case, Config will take these steps:

  1. Search for config.yaml in the current working directory.
  2. If not found, search for ~/.config/app/config.yaml.
  3. If still no file exists, create a default config at ~/.config/app/config.yaml

If we get to step 3, but then create a new config at ./config.yaml, this will take priority over the one found at ~/.config/app/config.yaml.

Example

See usage.py for an example.

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

configlite-0.2.3.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

configlite-0.2.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file configlite-0.2.3.tar.gz.

File metadata

  • Download URL: configlite-0.2.3.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for configlite-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a007abd037723acf5c78f8ab64a2e87834e458ae8be5fdf5682ae50b5c75dcbc
MD5 1acfa223ec12f43472fe975848863127
BLAKE2b-256 33b0c2a3ec9ba428d190082f65b8af1c6231dc497fbfe1b266f0019c9c6cdcde

See more details on using hashes here.

Provenance

The following attestation bundles were made for configlite-0.2.3.tar.gz:

Publisher: push-to-pypi.yml on ljbeal/ConfigLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file configlite-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: configlite-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for configlite-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 194748db386e3252e5ffd8b5db9b3a12458c6b7746f3697b8017c2dc2d63143c
MD5 678d4058b38279620d4b4e6939e72a3f
BLAKE2b-256 2776af2103dd0d90e0e6c2a708c61dcb279eeaff3e55f6be80c326edc32966c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for configlite-0.2.3-py3-none-any.whl:

Publisher: push-to-pypi.yml on ljbeal/ConfigLite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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