Skip to main content

Application configuration inspired by Microsoft.Extensions.Configuration (.NET).

Project description

confeasy

Application configuration inspired by Microsoft.Extensions.Configuration (.NET).

The main idea is to have the following workflow:

  1. Define one or more configuration sources from where the actual configuration is created (or downloaded).
  2. Build the configuration. This basically means put everything into a big flat dictionary where lastly defined sources could override values from previous ones if they match on the configuration key.
  3. Use resulting configuration: a. Directly, picking up individual values by their key. b. Bind all or portion of the configuration to a strongly typed class instance (typically a dataclass) and use this instance instead of the configuration itself. The benefit is better intellisense in IDEs and more decoupling.

Getting started

Install the package.

poetry add confeasy
# or similar command for your package manager of choice

In python, usually around application start:

# DbOptions class is an illustrative example of strongly typed configuration.
class DbOptions:
    def __init__(self):
        self.connnection_string: str = ""
        self.max_connections: int = 100

from confeasy import Builder
from confeasy.jsonfile import JsonFile
from confeasy.envars import EnvironmentVariables
from confeasy.cmdline import CommandLine

# Order of the configuration sources matters; later sources can overwrite values from earlier ones.
builder = (Builder()
           .add_source(JsonFile()
                       .required("settings.json")
                       .optional("setting.local.json"))
           .add_source(EnvironmentVariables(prefix="MYAPP_"))
           .add_source(CommandLine()))

config = builder.build()

# Bind configuration to a class instance and pass the instance to other objects.
options = config.bind(DbOptions(), prefix="db")

# OR pick up individual values:
db_conn_str = config.get_value("db.connection_string")

Out-of-the-box configuration sources

  • JSON files
  • command line arguments
  • environment variables

Additional configuration sources

Development

For developer related information, check Developer Guide.

Near future:

  • Support for TOML files using tomllib from standard library.

Never:

  • YAML files will not be supported unless a parsing module is available in the standard library.
  • INI files will not be supported, as they are not well-suited for handling hierarchical structures that application configuration often evolve towards.

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

confeasy-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

confeasy-0.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file confeasy-0.0.1.tar.gz.

File metadata

  • Download URL: confeasy-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.5.0-1025-azure

File hashes

Hashes for confeasy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5940bf302f9d461d8def333ca8365a0482fd4fa9b128e699e25b96323e079cc2
MD5 5e091c33c52fd90eb1dde21b801edbb3
BLAKE2b-256 a95d5df30a7199e2d9b72dc44649e2c3b46eff2f72639708318cf65fd758ec6b

See more details on using hashes here.

File details

Details for the file confeasy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: confeasy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.5.0-1025-azure

File hashes

Hashes for confeasy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 111c8b7dab0bc14ef07dc66389a0374f109f55b53e2da64530aa0d8d18b5ed37
MD5 0a6321e7f31af13797b9c7b1172bee27
BLAKE2b-256 7c32ed8e87d22e535a34eb931b7c844b8fdb7abd75ac25b00b6c0f97518cb347

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