Configuration module, that provides a way to manage configs structure, validation and casting to type inside your code. Based on pedantic models. Additionally it can automatically getting config from environment variables, .env, HashiCorp Vault, etc.
Project description
bc-config
Make configuring your application easier.
Installing
pip install bc-configs
Make your custom config class
import os
from bc_configs import BaseConfig, define
define()
class MyConfig(BaseConfig):
some_int: int
some_string: str
some_bool: bool
my_config = MyConfig() # type: ignore[call-arg]
assert int(os.getenv("MY_SOME_INT")) == my_config.some_int # True
assert os.getenv("MY_SOME_STRING") == my_config.some_string # True
assert bool(os.getenv("MY_SOME_BOOL")) == my_config.some_bool # True
The name of the environment variable is formed based on the names of the class and field.
Features
- Load environment variables from
.envfiles (usingpython-dotenv). - Load environment variables from YAML files (e.g.,
.env.ymlor custom path viaYAML_CONFIG_FILEenvironment variable). - Load secrets from HashiCorp Vault (using
hvac).
Error handling
When a required configuration field is missing, the library raises a ValidationError with an enriched error message that includes the environment variable name:
ValidationError: 1 validation error for MyConfig
some_int
Field required → env var: 'MY_SOME_INT' (description: Database port number) [type=missing, input_value={}, input_type=dict]
If the field has a description, it will be included in the error message:
class MyConfig(BaseConfig):
some_int: int = Field(description="Database port number")
Error message:
ValidationError: 1 validation error for MyConfig
some_int
Field required → env var: 'MY_SOME_INT' [type=missing, input_value={}, input_type=dict]
Project details
Release history Release notifications | RSS feed
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 bc_configs-0.4.1.tar.gz.
File metadata
- Download URL: bc_configs-0.4.1.tar.gz
- Upload date:
- Size: 286.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49c37dc6e8fb7e4a245a56735f6c56909d05093e7aa5910ff884cc0d726052a3
|
|
| MD5 |
958b18cf8253c4a6b5394104f1aa5107
|
|
| BLAKE2b-256 |
807e4029072e09d161794ec8ef8f5ac75f1ac12d586412b03d2eeea40d039a4c
|
File details
Details for the file bc_configs-0.4.1-py3-none-any.whl.
File metadata
- Download URL: bc_configs-0.4.1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94fee499efcad29d8a96bc300a3b6451b67653051e34089616c2aea955dfd8b1
|
|
| MD5 |
81e18139322fd4e5b0b0c6d18c7c7fd1
|
|
| BLAKE2b-256 |
06cfc0e79376909fa19a417fbe44585b6717eec57a6a3b5ae9b2efe21747e0a9
|