Read, write, validate, and migrate JSON-backed config classes.
Project description
config-as-json
config-as-json helps an application keep its configuration schema in a
Python class while storing actual configuration data in JSON files.
The intended usage model is:
- Derive an application-specific class from
config_as_json.Config. - Add one instance attribute per supported configuration parameter. An instance attribute can also be a dict or list, optionally with nested dicts and lists.
- Let the values assigned in the derived constructor act as the default configuration.
- Use the library to write those defaults as JSON and to read JSON back into the derived configuration object.
The library is designed to support evolving configuration formats by letting applications define:
- custom parsers for values that should become richer Python types
- optional keys that receive default values when omitted
- backward-compatible key renames for older configuration files
- hooks that can warn or report when automatic compatibility changes were needed
Installation
config-as-json requires Python 3.12 or newer.
pip install --upgrade config-as-json
Main entry points
config_as_json.ConfigBase class for JSON-backed configuration objects.config_as_json.config_factory_from_jsonSelect the correct configuration class by inspecting JSON input.config_as_json.ConfigAutoChangeHookReceive notifications about automatic changes during parsing.config_as_json.MigrateCfgWarnHookWarn when backward compatibility was used.config_as_json.migrate_cfgRead an older configuration file and write it back in the newest supported format.
The generated API reference also shows the implementation modules where these public objects are defined.
Documentation and examples
- Example directory: example/src/example/README.md
- Public API notes: doc/api.md
- Protected/internal API notes: doc/protected_api.md
- Source repository: config_as_json
The example directory contains worked examples for new users. It is not included in the package installed from PyPI.
Project status
This package originated as configuration code from a larger application and has been refactored into a stand-alone reusable library. The public API reference and worked examples are maintained in the source repository.
License
MIT
Test summary
- Test result: 3563 passed in 9s
- No flake8 warnings.
- No mypy errors found.
- Built version(s): 0.3
- Build and test using Python 3.14.3
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 config_as_json-0.3.tar.gz.
File metadata
- Download URL: config_as_json-0.3.tar.gz
- Upload date:
- Size: 43.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dec62bd2107867b17b02a0ca47b7448e708c82245aa5f021f98ab04d24f8b2e
|
|
| MD5 |
f96143e4ea87a51e9caa3273479aaf7f
|
|
| BLAKE2b-256 |
6fca8567ca4afd31a03f460ed2a78949b3410ffed695679620ef15b0a6c6adcf
|
File details
Details for the file config_as_json-0.3-py3-none-any.whl.
File metadata
- Download URL: config_as_json-0.3-py3-none-any.whl
- Upload date:
- Size: 51.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0425a97be39d1ecb8361edad26188bf02139560ea515825673fee0fb2d01f478
|
|
| MD5 |
aecbff2a05247802a6ef073bf62a1c31
|
|
| BLAKE2b-256 |
eb4488557e2267aeff9e1fe3578304f2cf5988110338d7cf42a7a068036a6251
|