A simple configuration module
Project description
Configureout
A lightweight and flexible configuration loader for Python. Supports loading configuration from dicts, JSON strings, or files, with namespace-style access.
Features
- Load config from dict, JSON string, or file
- Automatically converts nested structures to
SimpleNamespace - Modify, save, and update configurations easily
- Dictionary-style and attribute-style access
- Prevents reloading after initial load
Installation
You can install configureout via pip:
pip install configureout
Or just include configureout.py in your project.
Usage
from configureout import Config
# Load from file
cfg = Config('config.json')
# Or load from dict
cfg = Config({'debug': True, 'db': {'host': 'localhost'}})
#Or load from JSON string
cfg = Config('{"debug": true, "db": {"host": "localhost"}}')
print(cfg.db.host) # localhost
Public Methods
cfg.to_dict() # Converts the internal namespace config to a standard Python dictionary.
cfg.save(config_path=None, **kwargs) # Saves the current configuration to a JSON file. (Attribute "config_path" is required for non-file configs.)
cfg.update(other=None, **kwargs) # Updates the configuration with new values (from dict or keyword args).
cfg.copy() # Returns a copy of the current configuration.
cfg.keys() / cfg.values() / cfg.items() / cfg.get(key, default=None) # Standard dictionary-style access methods.
Magic Methods
__getitem__(key) / __setitem__(key, value) # Enables dict-style access: cfg['key'].
__delattr__(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.
Python Version
Python 3.8+ 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
configureout-2.0.tar.gz
(3.4 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
File details
Details for the file configureout-2.0.tar.gz.
File metadata
- Download URL: configureout-2.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c51b7c2118c063d1e9fc28498de4c3f2476f9e45dc26adc302cc537403984cb7
|
|
| MD5 |
cac3b6380c860e8c71de8f348615b6a5
|
|
| BLAKE2b-256 |
2f146fd94a5605790ec645384b4cccfb1383f80eb7a450e41fff5483792c4893
|
File details
Details for the file configureout-2.0-py3-none-any.whl.
File metadata
- Download URL: configureout-2.0-py3-none-any.whl
- Upload date:
- Size: 3.5 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 |
af1fbdb8fc4fed76df0a8ab1228a6257f21c0a0a9ca8fd8e0f4f02a7cb6ca2a2
|
|
| MD5 |
425d16728a784d4006c1f79f0c5a6f68
|
|
| BLAKE2b-256 |
a6cbc091a571bfdbbdb7f7291547121c03c42154b77c667c18f8008fec3e11ad
|