Skip to main content

Explicitly versioned JSON serialisation

Project description

WARNING

bream is currently in pre-alpha development, and does NOT yet have a stable serialisation format.

Any release in the 0.0.x series may contain breaking changes.

Please do test-drive and give feedback, or else check back soon for a stable version!

END WARNING


bream

bream is an explictly versioned encode/decode framework targetting JSON-like trees.

Goals and non-goals

bream aims to be the following:

  • Simple: encode to a human-readable JSON tree.
  • Explicit: no silent conversion. User-provided versions, easy upgrades.
  • Modular: bring-your-own codecs.

It does not aim to be fast. Speed isn't a current design goal.

Data structure

A JSON-like tree is a nested combination of dict (with str keys only), list, int, float, str, bool and None.

An bream tree is a dict with some metadata and a payload; any valid JSON tree is a valid payload. For example:

{
    "_bream_spec": 1,
    "_payload": {
        "serialised": ["data", "goes", "here"]
    }
}

Any JSON tree is a valid bream payload.

Encoded objects

Certain JSON trees within a payload represent 'encoded' Python objects. Any such tree is a dict with a particular structure. Here's how complex(0.123, 0.456) might be encoded:

{
    "_type_label": "complex",
    "_version": 1,
    "_payload": {
        "real": 0.123,
        "imag": 0.456
    }
}

The three top-level fields are special:

  • _type_label is a unique label for the type.
  • _version is incremented whenever the structure of _payload needs to change.
  • _payload is some JSON data (that may or may not be a dict).

A Coder is an object which knows how to convert from the payload back to a Python object.

Advantages of versioning

The main advantage of explicitly encoding & decoding your objects with bream is the ability to version the encoded form, and then provide a "compatibility decode" pathway to decode an older encoded representation into the latest in-memory representation.

This also means that upgrading an 'old' file on disk is as simple as decoding then encoding again.

Separating the Coders from the type being encoded also has the advantage that you can write custom serialisation for builtin or third-party types not under your direct control.

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

bream-0.0.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

bream-0.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file bream-0.0.1.tar.gz.

File metadata

  • Download URL: bream-0.0.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for bream-0.0.1.tar.gz
Algorithm Hash digest
SHA256 8dd253d97464a94dc59bbcd996635043575fa085b4705d75dc55ecc659ee7b73
MD5 cc0c97350586faf8038f01cc446f08ff
BLAKE2b-256 4f615e7df3a01c89516e8022f2fe32b1f945e7313d0dae9bc535944c60d71f63

See more details on using hashes here.

File details

Details for the file bream-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bream-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for bream-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f882928cdfad613120a170a106bbe611765d7f2832485ae00febbf39574e8893
MD5 c4897f4c4a5854db1237ee512c3f0638
BLAKE2b-256 1a73e4a220e103eb1df3987d8b4178373b0b42b102201360716c2abfda726aa2

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