A versatile Python library for loading and managing configuration files (JSON, YAML, XML, TOML, and INI/DEF-style) with attribute-style access, merging capabilities.
Project description
loadstructure
A versatile Python library for loading and managing configuration files (JSON, YAML, XML, TOML, and INI/DEF-style) with attribute-style access, merging capabilities.
✨ Features
- Multiple Formats: Load configurations from JSON, YAML, XML, TOML, and INI/DEF files.
- Attribute Access: Access settings using dot notation (e.g.,
config.server.port). - Merging: Easily merge multiple configuration files, with later files overriding earlier settings.
- Saving: Write your data in form of dictionary back to any supported file format.
Installation
Using uv:
uv add loadstructure
Using pip
pip install loadstructure
📦 Dependencies
The following dependencies are required and will be installed automatically if you use standard Python packaging practices:
- YAML:
pyyaml >=6.0.3 - TOML:
toml >=0.10.2 - XML:
xmltodict >=1.0.2
📖 Usage
Basic Loading
Instantiate ConfigManager with the path to your config file and call .load().
config.json:
{
"app": {
"name": "App",
"version": "1.0.0",
"features": {
"login": true,
"analytics": false,
"dark_mode": true,
"notifications": true
},
"ui": {
"theme": "light",
"language": "en"
}
},
"modules": {
"editor": {
"enabled": true,
"autosave_interval": 5
},
"export": {
"formats": ["pdf", "html", "md"],
"compress_output": false
}
}
}
Load a configuration file
from loadstructure import ConfigManager
cfg = ConfigManager("app_config.json")
cfg.load()
# Attribute-style access
print(cfg.app.name) # App
print(cfg.app.ui.theme) # light
print(cfg.modules.editor.autosave_interval) # 5
# Dictionary-style access
print(cfg["app"]["features"]["dark_mode"]) # True
Nested key access using dotted paths
theme = cfg.get("app.ui.theme")
print(theme) # light
Modifying and saving values
cfg.app.features.analytics = True
cfg.modules.export.compress_output = True
fg.app.tech = {
'frontend':'(html,css,js)',
'backend':'electron'
}
# Save changes back to JSON
cfg.save()
Write
Merging multiple configuration files
# app_config_override.json can override some settings
merged_cfg = ConfigManager.merge(["app_config.json", "app_config_override.json"])
print(merged_cfg.app.features.analytics)
License
This project is licensed under the MIT License for full details.
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 loadstructure-0.1.0.tar.gz.
File metadata
- Download URL: loadstructure-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
879a11b0dd3ade65a75d22fdad503b652cdbb9a917d46f84c8d8108a6a4edfa9
|
|
| MD5 |
09aaf2208e6580036c756e3dbfc9823b
|
|
| BLAKE2b-256 |
3ae2a2d7482ee3572d1f76e2fa30d5d88a7bbe82ab82ffff37c247b6e592388b
|
File details
Details for the file loadstructure-0.1.0-py3-none-any.whl.
File metadata
- Download URL: loadstructure-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1738478d82620d2a43ec29bb3f70180bedef6a8e9133364e98e9939c0d0339d4
|
|
| MD5 |
390ca3a7b700fa2183b15a225830d34c
|
|
| BLAKE2b-256 |
6792b59434fd4532835b1a820d9c9c2aa933de4178675fa2a0aa820ac82bb27e
|