A lightweight and flexible configuration loader for Python.
Project description
Configureout
A lightweight and flexible configuration loader for Python. Supports loading configuration from dicts, JSON/JSONC strings, or files, with namespace-style access.
Features
- Load config from dict, JSON string, or file
- Automatically converts nested structures to
Config - Modify, save, and update configurations easily
- Dictionary-style and attribute-style access
Installation
You can install configureout via pip:
pip install configureout
Usage
from configureout import Config
# Load from file
cfg = Config('config.json')
print(cfg.get('debug')) # True
# Or load from dict
cfg = Config({'debug': True, 'db': {'host': 'localhost', 'port': 8000}})
print(cfg.db.host) # localhost
# Or load from JSON string
cfg = Config('{"debug": true, "db": {"host": "localhost", "port": 8000}}')
print(cfg['db']['port']) # 8000
Public Methods
# Converts the internal namespace config to a standard Python dictionary.
to_dict()
# Saves the current configuration to a JSON file. (Attribute "config_path" is required for non-file configs or nested objects.)
save(config_path=None, **kwargs)
# Updates the configuration with new values (from dict or keyword args).
update(other=None, **kwargs)
# Removes all nested elements from config.
clear()
# Returns a copy of the current configuration.
copy()
# Standard dictionary-style access methods.
keys() / values() / items() / get(key, default=None) / pop(key) / popitem()
Magic Methods
__getitem__(key) / __setitem__(key, value) # Enables dict-style access: cfg['key'].
__delitem__(key) # Deletes a config attribute.
__contains__(key) # Checks if key exists using 'key' in cfg.
__len__() # Returns the number of keys.
__iter__() # Enables iteration over keys.
__str__() # Returns a formatted JSON string of the config.
__repr__() # Developer-friendly representation of the config.
__bool__() # Returns False if the config is empty.
__eq__(other) # Compares config with another Config or dict.
__or__(other) / __ior__(other) # Merge configs using | and |= operators.
__reduce__() # Supports pickling.
Restrictions
Attempting to override public methods will raise an error:
cfg.update = "not allowed" # Raises LockedMethodError
Python Version
Python 3.9+ is required.
License
MIT License
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 configureout-2.1.tar.gz.
File metadata
- Download URL: configureout-2.1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
427e906f840a2bf7a1225a123f210c32a210d3782e2197d874a467eb97e3e973
|
|
| MD5 |
7e9c00cee09478661d0dd1281622ebe3
|
|
| BLAKE2b-256 |
e09336aa98db0e2fd365d0722a15d3806de0173d9d165c95826598a9c6b6576a
|
File details
Details for the file configureout-2.1-py3-none-any.whl.
File metadata
- Download URL: configureout-2.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2348a33f4c0cbbe740138f2c50c6fbabbda6cd91a9da0315070218c69b7398a
|
|
| MD5 |
022ea1e308f7bcf6a9c1b38988a2b008
|
|
| BLAKE2b-256 |
3bcdfa5b74676489cd5c34a3a47eb1beb3985acc591374409209afa224a3913a
|