Skip to main content

typed 12-factor app configuration helper

Project description

basecfg

basecfg is a Python library designed to simplify and standardize the process of configuring a Python application, particularly a Dockerized application.

Users of this library create a class which inherits from basecfg.BaseCfg. For each configuration option an app should support, a type-annotated class attribute is defined using a call to opt.

Once a config class is instantiated it automatically populates the configuration from these sources:

  1. default values declared in the configuration class
  2. a JSON config file (such as a Kubernetes ConfigMap)
  3. a .env file (in docker run envfile format)
  4. environment variables
  5. docker secrets
  6. command-line arguments

Example

This file is an excerpt from a more extensive example implementation of the library:

#!/usr/bin/env python3
from typing import Optional

from basecfg import BaseCfg, opt


class ExampleAppConf(BaseCfg):
    server_username: str = opt(
        default="demoperson",
        doc="The username to use on the server",
    )
    server_password: Optional[str] = opt(
        default=None,
        doc="The password to use on the server",
        redact=True,
    )
    verbose: bool = opt(
        default=False,
        doc="whether to log verbosely",
    )
    batch_size: Optional[int] = opt(
        default=None,
        doc="how many objects to transfer at a time",
    )

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

basecfg-2.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

basecfg-2.1.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file basecfg-2.1.0.tar.gz.

File metadata

  • Download URL: basecfg-2.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for basecfg-2.1.0.tar.gz
Algorithm Hash digest
SHA256 edb872cda3673fb9dbc7689fc4f8735d37726f58ad57c068328134c6594ff5c4
MD5 e5d7bf39ae42476dd22cc3fd945e1ab2
BLAKE2b-256 338d8c985bbd3959d3e6a71f12643bfbee8489a683ae5ca313244475c33551f0

See more details on using hashes here.

File details

Details for the file basecfg-2.1.0-py3-none-any.whl.

File metadata

  • Download URL: basecfg-2.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for basecfg-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0550e8ad38490e19fb1c16c79d069f087e4bbb6a8cba5313608034a90888c593
MD5 fb0c09ab67b347ac19a83035d22865cc
BLAKE2b-256 04b53f3381a9b930f5c95fa5ae5f36925ea7c5559e22d716a65111bfd1c04070

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