A simple API to manipulate configuration files
Project description
Hectiq Config
This Python module provides a powerful and flexible configuration management system based on Pydantic models. It is designed to create, manage, and validate configurations with ease.
Features
- Dynamic Configuration Classes: Utilize Pydantic to dynamically create configuration models from dictionaries.
- Validation and Casting: Validate configurations against a defined template and cast configurations to ensure correct types and structures.
- Serialization and Deserialization: Load and save configurations from and to JSON files using
orjson
for efficient IO operations. - Nested Configurations: Support for nested configurations, allowing complex, hierarchical settings to be managed cleanly and efficiently.
Dependencies
pydantic
: Used for creating data models and validation.orjson
: Used for fast JSON serialization and deserialization.re
: Used for regex operations, particularly in handling aliases in configuration keys.
Installation
pip install hectiq-config
Usage
Creating a Configuration
from hectiq_config import Config
config = Config(a="12345", b=12345, c=[1, 2, 3], d={"x": 1, "y": 2})
Loading and Saving Configurations
config.save('path/to/config.json')
loaded_config = Config.load('path/to/config.json')
Validating Configurations
You can validate a configuration against a template to ensure it has the correct structure and types. A template is a dictionary that defines the expected structure of the configuration.
For example, define a template as follows:
template = {
"a": str,
"b": int,
"c": list,
"d": {
"x": int,
"y": int
}
}
Then validate the configuration against the template:
is_valid = config.validate(template=template, raise_exception=True)
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
hectiq_config-1.0.0.tar.gz
(5.7 kB
view hashes)
Built Distribution
Close
Hashes for hectiq_config-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41fa3ee1a9df458352d27534f6615820cbf711487abeff1b4309dfce7f7a95a0 |
|
MD5 | cf212fa76cbcf3fbe7b2ec1fc8751757 |
|
BLAKE2b-256 | 1788c14f34779badcbb168ca2f8b08bd9cc6a95b58e386ed92883768d0a242e8 |