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

image image image Actions status

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.2.tar.gz (11.1 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.2-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bream-0.0.2.tar.gz
Algorithm Hash digest
SHA256 e0a3f891ec28b7577d3b0d42cc292be200c291431b42b5a4a528e3872f3033f7
MD5 ba247118af84e41e091bc32e6d7a37d8
BLAKE2b-256 6ea8c7f8e521772818d7782b78a25ce5ca0e0095276bc0f277bba466c4d1bb9d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bream-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e1f45c444094db875a71e688f0316c36a7eb97ad4319e3d0b44cbb9242f395ff
MD5 2c8960bc3013e629ffcc9201f8c0ea0a
BLAKE2b-256 68de11c3991d3954446a908199d0b67494f0659e3356ae57cea33a856835f08a

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