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: 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 |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minicfg-3.0.2.tar.gz.
File metadata
- Download URL: minicfg-3.0.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0af6bf278c606ebdfc27379477c811884680fcd3b77157d28f70164d9f54c98
|
|
| MD5 |
36b3e873e4f693fb5c61a6756c35df2b
|
|
| BLAKE2b-256 |
9968d6c9e952a5f986524e57be9059bffdc51c8780ae8cc818b9c4854fe74663
|
File details
Details for the file minicfg-3.0.2-py3-none-any.whl.
File metadata
- Download URL: minicfg-3.0.2-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.22.4 CPython/3.12.3 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55597b62cc1755a5a41139514e73a1500ffe79193793f80647286fda85d702fe
|
|
| MD5 |
36850680457c84da10982f1f1bf32b19
|
|
| BLAKE2b-256 |
28971ef442086c45ac896c10dbb456f40810c04159d9e8b3ccc44eb84b86c992
|