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). - Auto-Creation: Automatically creates nested keys if they do not exist.
- Schema Validation: Enforce types and structure with optional schema support.
- Merging: Merge multiple configuration files, with later files overriding earlier settings.
- Update & Replace: Update partial configs with
.update()or replace entire configs with.replace(). - Saving: Save your configuration back to the original or new 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
config = ConfigManager("app_config.json")
cfg = config.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
Schema validation
config = ConfigManager("config.json", schema={
"app": {"name": str, "version": str},
"modules": dict
})
cfg = config.load()
cfg.app.name = "MyApp" # valid
cfg.app.version = 2 # raises SchemaError because type must be str
Updating and replacing configurations
# Update part of the config
cfg.update({
"app": {
"version": "1.1.0"
}
})
# Replace entire config
cfg.replace({
"app": {
"name": "NewApp",
"version": "2.0.0"
}
})
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
config.save()
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.
Metadata
Release files for loadstructure 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| loadstructure-0.2.2.tar.gz | 10.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loadstructure-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.9 kB
Release files / loadstructure-0.2.2.tar.gz
| Download URL | loadstructure-0.2.2.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c032c94c4379de2776862d45747ecd65e581480fa0b8405a9ebcbc4494a3cfa2
|
|
BLAKE2b-256 checksum How to use checksums |
33cf38d2736a478cdd16cad95859e1da8961963fa3a49661a64b0a9b085fba61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / loadstructure-0.2.2-py3-none-any.whl
| Download URL | loadstructure-0.2.2-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6e381ab9aa07737a2a3f34ab14697fa76e9c042e4a71642c66308689c3269a1
|
|
BLAKE2b-256 checksum How to use checksums |
3234213ae5efdce3be184515c3ba3bfdacc488a3b91b0ba03aff77306b921c18
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|