Skip to main content

minicfg is a lightweight, minimalistic and easy-to-use configuration package for your Python services.

Project description

minicfg

📑 minicfg is a lightweight, minimalistic and easy-to-use configuration package for your Python services.

Features

  • Lightweight: minicfg is a small package with no dependencies.
  • Easy to use: minicfg provides a simple API to define and populate configurations.
  • Documentation: generate documentation for your configuration.
  • Type casting: minicfg supports type casting for the fields. You can also define your own casters.
  • File field attachment: minicfg supports attaching a virtual file field to a field.
  • Prefixing: minicfg supports prefixing the fields with a custom name prefix.
  • Nested configurations: minicfg supports nested configurations.
  • Custom providers: minicfg supports custom providers to populate the configuration from different sources.

Installation

Just install minicfg using your favorite package manager, for example:

pip install minicfg

Usage

from minicfg import Minicfg, Field, minicfg_name
from minicfg.caster import IntCaster


@minicfg_name("SERVICE")
class MyConfig(Minicfg):
    @minicfg_name("DATABASE")
    class Database(Minicfg):
        HOST = Field(attach_file_field=True, description="database host")
        PORT = Field(default=5432, caster=IntCaster(), description="database port")

    @minicfg_name("EXTERNAL_API")
    class ExternalAPI(Minicfg):
        KEY = Field(description="external API key")
        USER_ID = Field(caster=IntCaster(), description="external API user ID")


if __name__ == '__main__':
    config = MyConfig()  # create an instance of the configuration
    config.populate()  # populate the configuration from the environment variables

    print(f"connect to database at {config.Database.HOST}:{config.Database.PORT}")
    print(f"external API key: {config.ExternalAPI.KEY}")
    print(f"external API user: {config.ExternalAPI.USER_ID}")

Try running the script with the following environment variables:

  • SERVICE_DATABASE_HOST=example.com
  • SERVICE_DATABASE_PORT=5432
  • SERVICE_EXTERNAL_API_KEY=token
  • SERVICE_EXTERNAL_API_USER_ID=123

And you should see the following output:

connect to database at example.com:5432
external API key: token
external API user: 123

More examples are available here.

Documentation generation

You can use minicfg script to generate documentation for your configuration.

For example, minicifg --format=markdown example.MyConfig will generate documentation for the MyConfig class above, and it would look like this:

SERVICE

Name Type Default Description

SERVICE_DATABASE

Name Type Default Description
SERVICE_DATABASE_HOST str N/A database host
SERVICE_DATABASE_HOST_FILE str N/A database host file
SERVICE_DATABASE_PORT int 5432 database port

SERVICE_EXTERNAL_API

Name Type Default Description
SERVICE_EXTERNAL_API_KEY str N/A external API key
SERVICE_EXTERNAL_API_USER_ID int N/A external API user ID

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

minicfg-3.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

minicfg-3.0.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file minicfg-3.0.0.tar.gz.

File metadata

  • Download URL: minicfg-3.0.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.1 CPython/3.12.3 Linux/6.8.0-1017-azure

File hashes

Hashes for minicfg-3.0.0.tar.gz
Algorithm Hash digest
SHA256 56b07dc496cba0e44ae0ea727ebc372468fe632c0d1121efb26819d6d717eb4e
MD5 16fc0f4380ac0c842f64a8dc55998f5e
BLAKE2b-256 e8a80ca9552dc0914146779e4ed1c0b5a724607eae3e79198ee9802e8ccf0378

See more details on using hashes here.

File details

Details for the file minicfg-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: minicfg-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.22.1 CPython/3.12.3 Linux/6.8.0-1017-azure

File hashes

Hashes for minicfg-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c8b63f72f7d8a673864b6fc8baed2de1ef3171492ed53f29767ccad9a1ee551
MD5 612ce451bb6eaa0269944b05a51f0bba
BLAKE2b-256 f840c36141d308ec2409e5f33b2301ee067cb369ce313c03e5e7117b32236871

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