Configuration add-on to Dynaconf
Project description
About
Сonfhub is a library that relieves developers of the tedious task of creating and managing configuration files. Instead of wasting valuable time writing configurations, developers can focus on building the site's functionality.
History
Based on our own experience and the experience of our colleagues, we realized that the process of working with configurations had become a real burden. We wanted something simple and effective. After several weeks of testing our MVP, we identified the strengths and weaknesses and presented the first alpha version of confhub to the world. Despite its shortcomings, it showed prospects for development.
Updated version (>= 0.1.0.5a)
We currently offer a significantly improved version of confhub, which has extensive functionality. You can now dynamically generate configurations from model classes, greatly simplifying the process. In addition, the library supports developer mode, which speeds up the process of replacing configurations several times.
Documentation
Getting started with confhub
Installation and initialization
To get started with confhub, you need to create a project and install the Python virtual environment. Then install the confhub library into the virtual environment.
pip install confhub
After installing the library, initialize it in your project with the following command:
confhub init <folder>
Where <folder>
is the name of the folder where the entire configuration structure will be placed. For example:
confhub init configurations
This command will create the following structure in the root of your project:
.service.yml
: Contains basic settings such as paths to configs and models. The file is automatically added to.gitignore
.configurations/
: A folder created at your request.config/
: A folder to store the generated configuration files.models.py
: A file for describing models. Initially contains an example PostgreSQL model.
Creating Models
In models.py
you can describe your models. For example:
from confhub import BlockCore, field
class PostgreSQL(BlockCore):
__block__ = 'postgresql'
scheme = field(str)
host = field(str, development_mode=True)
port = field(int, secret=True)
user = field(str, secret=True)
password = field(str, secret=True)
path = field(str, secret=True)
class ItemBlock(BlockCore):
__block__ = 'item_block'
item_name = field(str)
class TestBlock(BlockCore):
__block__ = 'test_block'
item_block = ItemBlock()
illuminati = field(str, filename='illuminati')
admins = field(str)
Generation of configuration files
After creating models, you can generate configuration files using the command:
confhub generate_models
This command converts your models into configuration files with a .yml
extension.
Confhub generates two main files: settings
and .secrets
. The secrets are automatically added to .gitignore
. You can also specify filename
in models to create additional files in the config
folder.
Do not use secrets
and filename
at the same time. There may be unexpected consequences at this point!
This documentation will help you get started with confhub and use its features to simplify the process of working with configurations in your project.
Filling configurations
Fill in the configurations, e.g:
postgresql:
password: str; qwer
path: str; db_confhub
port: int; 5432
user: str; morington
The data type is specified before the value. Available types: str
, int
, bool
, float
. YML also supports lists, in models we prescribe a type for the value of each element in a list, and with YML we make a list:
admins:
- str; Adam
- str; John
- str; Saly
Read configurations
To read configurations, use the following code:
import structlog
from confhub import Confhub
from confhub.setup_logger import LoggerReg
logger = structlog.get_logger(__name__)
if __name__ == '__main__':
config = Confhub(developer_mode=True, logger_regs=[
LoggerReg(name="", level=LoggerReg.Level.DEBUG,)
]).data
logger.info("PostgreSQL", host=config.postgresql.host)
logger.info("Admins", host=config.test.admins)
Logging Configuration
Sonfhub uses structlog
for logging. You can configure loggers using LoggerReg
:
LoggerReg(name="", level=LoggerReg.Level.DEBUG)
developer_mode
The developer_mode
argument is available both in the Confhub
class and in the .service.yml
file. The class argument takes precedence over the file.
Main developers
Adam Morington
License
Сonfhub is distributed under the MIT license. This means that you are free to use, modify and distribute the library for any purpose, including commercial use.
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
File details
Details for the file confhub-0.1.0.6a0.tar.gz
.
File metadata
- Download URL: confhub-0.1.0.6a0.tar.gz
- Upload date:
- Size: 47.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7de9dda32444f17ece34f687d7ec1daaa82e1630aca775e174f982cae1118654 |
|
MD5 | 38defc6f068ad377a2c534c3ec1560b6 |
|
BLAKE2b-256 | 883f3b232bfb4b280650900c518c9b58ed3f5465629f47a9132c7f2afacc13aa |
File details
Details for the file confhub-0.1.0.6a0-py3-none-any.whl
.
File metadata
- Download URL: confhub-0.1.0.6a0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ceb7cae15748297f03fd730ca71756ed10dc6353fe22e074bbeae443d7e1c6a1 |
|
MD5 | da2e547515ed7a3d4421288390b2a152 |
|
BLAKE2b-256 | 324c1962135ce192162ce9c691c8f3fff35cfacf1cb12bd796dd86c736341238 |