Skip to main content

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 (or use multiple inheritance to derive from both a class with your paramaters and 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.Config Base class for JSON-backed configuration objects.
  • config_as_json.config_factory_from_json Select the correct configuration class by inspecting JSON input.
  • config_as_json.ConfigAutoChangeHook Receive notifications about automatic changes during parsing.
  • config_as_json.MigrateCfgWarnHook Warn when backward compatibility was used.
  • config_as_json.migrate_cfg Read 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

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: 3572 passed in 9s
  • No flake8 warnings.
  • No mypy errors found.
  • Built version(s): 0.4
  • Build and test using Python 3.14.4

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

config_as_json-0.4.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

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

config_as_json-0.4-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file config_as_json-0.4.tar.gz.

File metadata

  • Download URL: config_as_json-0.4.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.14.4

File hashes

Hashes for config_as_json-0.4.tar.gz
Algorithm Hash digest
SHA256 b1f38fd6d934e55f9ca6924c46794d6404198d13131df70319cb01db869c0460
MD5 b7e8df1e34e24e7d25edaf715307e67b
BLAKE2b-256 083f0678841a12290f1e5229a00cf74a74f67aa3f22ad1b7cd1f5d110c4fc2c5

See more details on using hashes here.

File details

Details for the file config_as_json-0.4-py3-none-any.whl.

File metadata

  • Download URL: config_as_json-0.4-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.14.4

File hashes

Hashes for config_as_json-0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4e9d96a21d39a1247ce8296386ed114aee07aed5b8349bcbeb0c7af2602df3be
MD5 9e44f6446f5954a1d255e1deeeb4c32d
BLAKE2b-256 800fb5a4f3f9b8759f6107b3b448bacaecddce9a40833969f69980cabfa4f8b5

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