Skip to main content

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

Or just configureout.py in your project.

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

configureout-2.3.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

configureout-2.3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file configureout-2.3.tar.gz.

File metadata

  • Download URL: configureout-2.3.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for configureout-2.3.tar.gz
Algorithm Hash digest
SHA256 e86b698f7926b19309afcabd297374c759374c4e39c0cfd083a33b1a9a0f59a1
MD5 9d80e1ce21e15c63c8da4b4df1b948b1
BLAKE2b-256 b64c9bd7ea7221ad5bc619e4c777438c339235a5fa612302ba8a4d27b16e20ff

See more details on using hashes here.

File details

Details for the file configureout-2.3-py3-none-any.whl.

File metadata

  • Download URL: configureout-2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for configureout-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b144fbf9723e30d5005911f110733af8138eb3bcf4dbe1555317903dc24be261
MD5 c584ecd9b83dd150eadef8f0d27776a8
BLAKE2b-256 d2dc41293e0c6a7c9b6f8614c631ce1fcd660e0f2311cb159dfa067fa397b44f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page