Skip to main content

Lightweight and opinionated config library for your Python services.

Project description

minicfg

Lightweight and opinionated config library for your Python services.

[!NOTE] Work in progress.

from minicfg.minicfg import Minicfg, minicfg_prefix
from minicfg.field import Field
from minicfg.caster import IntCaster

@minicfg_prefix("SERVICE")
class Env(Minicfg):
    @minicfg_prefix("BOT")
    class Bot(Minicfg):
        # SERVICE_BOT_TOKEN or SERVICE_BOT_TOKEN_FILE env var
        # will be used to populate TOKEN field value:
        TOKEN = Field(attach_file_field=True)

    @minicfg_prefix("MONGO")
    class Mongo(Minicfg):
        HOST = Field()
        PORT = Field(caster=IntCaster())  # PORT will be cast to int


env = Env()
env.populate()  # populate the config using env vars (by default)

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

# Run SERVICE_BOT_TOKEN=token SERVICE_MONGO_HOST=localhost SERVICE_MONGO_PORT=5432 python example.py
# Output:
# >>> Bot token: token
# >>> Mongo settings: localhost:5432

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-0.1.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

minicfg-0.1.0-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

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