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.0.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

basecfg-2.0.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for basecfg-2.0.0.tar.gz
Algorithm Hash digest
SHA256 287e14fc5e2815d5777845239ca2233f1605fd0bec938db530b71f4caed05f50
MD5 8933259964d26db45d777614bc5ddf16
BLAKE2b-256 4a1206fabf9fa688c9aa7b5057b44c6c9d3e0742b8251b5d5bf6544ae17d97a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: basecfg-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61cce0ddcc90eed96161b669ba05b731b60ed9e4d81c2ee0d14575950b9d8e26
MD5 f3acf90644fd5c5dbecd1f2ade817693
BLAKE2b-256 93591d2ad63cc7e04d76d45a3813d68d27655021f6c4886f6b36b763767300eb

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