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.
  • 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: 3397 passed in 9s
  • No flake8 warnings.
  • No mypy errors found.
  • Built version(s): 0.1
  • 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

config_as_json-0.1.tar.gz (38.2 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.1-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for config_as_json-0.1.tar.gz
Algorithm Hash digest
SHA256 d44d49e50a349354acf84efd4532b4eb0c7d509c4bc38c33279c64325aa26357
MD5 c2c10ed3287167e5542b6f03d7e7e2c3
BLAKE2b-256 16a5867971f870f5c22e43bb8575b05bc52d8a28a161817054e2c802421844ed

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for config_as_json-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 429b5e2287ec26cdaeffc83a0c0279cb36431979b009c2656dc412e44873312d
MD5 acba02fffa496cc3d716aa8fe5e4f7ec
BLAKE2b-256 465ddd4585d2b5fc23d30d85a743358ec834eaa379101b6df43fb1571b72a9a0

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