A Python library for managing hierarchical configurations using a class-based approach.
Project description
ccfg
A Python library for managing hierarchical configurations using a class-based approach.
Features
- Define configuration hierarchies using Python classes
- Automatically convert between configuration classes and dictionaries
- Support for multiple serialization formats (JSON, TOML, YAML)
- Simple file-based storage and retrieval
Installation
pip install ccfg
Usage Example
Below is a comprehensive example demonstrating the main features:
from ccfg import CCFG
class ApplicationConfig(CCFG):
# Custom path for file storage
path = "configs/app_settings.json"
# No explicit name, will use class name "ApplicationConfig" as default
class Database:
# Custom name for this section
name = "DatabaseSettings"
class Connection:
# No explicit name, will use "Connection" by default
value = "postgresql://user:password@localhost:5432/mydb"
class Pooling:
name = "ConnectionPool"
value = {"max_connections": 10, "timeout": 30}
class Logging:
# Using default name "Logging"
class Level:
value = "INFO"
class Output:
name = "OutputPath"
value = "/var/log/app.log"
class Features:
# Using a list for complex values
value = ["authentication", "api", "admin_panel"]
# Convert to dictionary
config_dict = ApplicationConfig.to_dict()
print(config_dict)
# Output:
# {
# "ApplicationConfig": {
# "DatabaseSettings": {
# "Connection": "postgresql://user:password@localhost:5432/mydb",
# "ConnectionPool": {"max_connections": 10, "timeout": 30}
# },
# "Logging": {
# "Level": "INFO",
# "OutputPath": "/var/log/app.log"
# },
# "Features": ["authentication", "api", "admin_panel"]
# }
# }
# Save to file using the configured path
ApplicationConfig.dump() # Saves to configs/app_settings.json
# Save to a different file in YAML format
ApplicationConfig.dump(form="yaml", path="configs/app_config.yaml")
# Load configuration
ApplicationConfig.load() # Loads from configs/app_settings.json
# Access configuration values
db_connection = ApplicationConfig.Database.Connection.value
log_level = ApplicationConfig.Logging.Level.value
features = ApplicationConfig.Features.value
print(f"Database connection: {db_connection}")
print(f"Log level: {log_level}")
print(f"Enabled features: {', '.join(features)}")
Supported Serialization Formats
- JSON (default)
- TOML
- YAML
License
MIT
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
ccfg-0.0.1.tar.gz
(6.3 kB
view details)
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
ccfg-0.0.1-py3-none-any.whl
(5.3 kB
view details)
File details
Details for the file ccfg-0.0.1.tar.gz.
File metadata
- Download URL: ccfg-0.0.1.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d83b950d1db55a8ff54c8226fe48e1ebaa431eff3dbf8ca7c65a71633625b0b
|
|
| MD5 |
d9d9251fddcb760e93cd590b909512a4
|
|
| BLAKE2b-256 |
3a8b44b69d041b9a838f63c18d0d5b03ce2a0adfb740213c2343bc670daf9f84
|
File details
Details for the file ccfg-0.0.1-py3-none-any.whl.
File metadata
- Download URL: ccfg-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48470ed3d58dc6a8c09fbced2d0db24366e802d2cc0552b3f506f7cf28f83a2c
|
|
| MD5 |
206462a1285137d44636ff28850cad7e
|
|
| BLAKE2b-256 |
20a2453281d90e6589b23b1420114fadcaaff8fdc77a2c05f4b79d81feda9884
|