Skip to main content

Lightweight and opinionated config library 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.
  • Type casting: minicfg supports type casting for the fields.
  • File attachment: minicfg supports attaching a file 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_prefix
from minicfg.caster import IntCaster

@minicfg_prefix("MYSERVICE")
class Env(Minicfg):
    @minicfg_prefix("BOT")
    class TelegramBot(Minicfg):
        # attach_file_field=True will read the value from the file provided in MYSERVICE_BOT_TOKEN_FILE env var
        # if no file is provided, it will read the value from MYSERVICE_BOT_TOKEN env var.
        TOKEN = Field(attach_file_field=True)
    
    class API1(Minicfg):  # <-- API1 class name will be used as a prefix for the fields inside it
        API_TOKEN = Field()  # API_TOKEN will be read from MYSERVICE_API1_API_TOKEN env var

    @minicfg_prefix("MONGO")
    class Mongo(Minicfg):
        HOST = Field()
        PORT = Field(caster=IntCaster())  # PORT will be casted to an integer type
        

# Populate the configuration from the environment variables:
env = Env.populated()

print(f"Bot token: {env.TelegramBot.TOKEN}")
print(f"Mongo settings: {env.Mongo.HOST}:{env.Mongo.PORT}")

"""
Try running the script with the following environment variables:
SERVICE_BOT_TOKEN=token SERVICE_MONGO_HOST=localhost SERVICE_MONGO_PORT=5432
And you will get

>>> Bot token: token
>>> Mongo settings: localhost:5432
"""

More examples are available here.

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

Uploaded Source

Built Distribution

minicfg-2.0.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minicfg-2.0.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for minicfg-2.0.0.tar.gz
Algorithm Hash digest
SHA256 1037240a5c38c5fdece266cfd0dd0ea43b93e1c2e5813cd9b76396cf63f88c7b
MD5 98cb05d064708948f688455dc4bb8d61
BLAKE2b-256 b458b6793b2018bbf0e9646c846c1729c27cea83c3b402f07cac40757ac6c121

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minicfg-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for minicfg-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f5e897b89ff7ff80f0102d30f2d155d4ec401fac6ad72eefa5e1faeff6312896
MD5 e07706189ec725f0fb8ac058da1ab7ec
BLAKE2b-256 17d3e3e4a88df157c83c6bd644f2e3d91a322be7453c48933e2a8543ea4a5fb2

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