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.1.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.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minicfg-3.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 74d8ca3bb8cce55fb4bbb246760c142d10199586ef8db85be06bd27ea3c7bbee
MD5 0dca2b9939391cf77d55a04df24a952b
BLAKE2b-256 c985f030773f25829f704e2c609c991249b3dd985b0c9137625e02f26dd7c3c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minicfg-3.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58efdcc1f3bf648b38c714f13cfadf110943742e1d7a89a27bc6d95c6cbf5712
MD5 84998b6cd38855941688b8491381f4ea
BLAKE2b-256 1dac9e12237aa46745d135b108793778890d1aed83a569f94decb355822d7f0c

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