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: 3440 passed in 9s
  • No flake8 warnings.
  • No mypy errors found.
  • Built version(s): 0.2
  • 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.2.tar.gz (39.7 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.2-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: config_as_json-0.2.tar.gz
  • Upload date:
  • Size: 39.7 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.2.tar.gz
Algorithm Hash digest
SHA256 98ccce2d149aa3d1452102960bb5f28d408017438034daa8d858caefc77730c5
MD5 29673ae2abf69562083414fd58c264c6
BLAKE2b-256 8f4d2e9c99368d7bae0f9b35879f2279a1abadc44de0dbd391f0931d6a297794

See more details on using hashes here.

File details

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

File metadata

  • Download URL: config_as_json-0.2-py3-none-any.whl
  • Upload date:
  • Size: 46.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ce8ab0f87bb88659556b68d455bf64c8dffc45a9334582998d6a785f511a38c4
MD5 6810975cb2f3b73a88436f37a0caebce
BLAKE2b-256 8ecc4c311813acdbe966e2960e787c902787310a2d987dca4c77b1a7ab60fd0a

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