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: str = Field(attach_file_field=True, description="database host")
PORT: int = Field(default=5432, caster=IntCaster(), description="database port")
@minicfg_name("EXTERNAL_API")
class ExternalAPI(Minicfg):
KEY: str = Field(description="external API key")
USER_ID: int = 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.comSERVICE_DATABASE_PORT=5432SERVICE_EXTERNAL_API_KEY=tokenSERVICE_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 |
Release files for minicfg 3.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| minicfg-3.0.2.tar.gz | 11.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| minicfg-3.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.2 kB
Release files / minicfg-3.0.2.tar.gz
| Download URL | minicfg-3.0.2.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b0af6bf278c606ebdfc27379477c811884680fcd3b77157d28f70164d9f54c98
|
|
BLAKE2b-256 checksum How to use checksums |
9968d6c9e952a5f986524e57be9059bffdc51c8780ae8cc818b9c4854fe74663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
|
Release files / minicfg-3.0.2-py3-none-any.whl
| Download URL | minicfg-3.0.2-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
55597b62cc1755a5a41139514e73a1500ffe79193793f80647286fda85d702fe
|
|
BLAKE2b-256 checksum How to use checksums |
28971ef442086c45ac896c10dbb456f40810c04159d9e8b3ccc44eb84b86c992
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
|