zodb-json-codec#

zodb-json-codec logo

Fast pickle-to-JSON transcoder for ZODB, implemented in Rust via PyO3.

Converts ZODB pickle records into human-readable, JSONB-queryable JSON while staying round-trip safe. Designed as the codec layer for a PostgreSQL JSONB storage backend.

Key capabilities:

  • Round-trip safe: encode to JSON and back yields a pickle that unpickles to an equal object (the bytes differ: memo puts are dropped and the header is rewritten, see JSON format)

  • Human-readable JSON with compact type markers (@dt, @ref, @t, …)

  • JSONB-queryable output for PostgreSQL

  • Faster than CPython’s C pickle extension on most operations

  • GIL released during Rust phases for multi-threaded Python

  • Direct JSON string path for zero-copy PostgreSQL storage

  • BTree flattening for all BTrees package types

  • Escape hatch (@pkl) ensures any pickle data roundtrips safely

Requirements: Python 3.12+, Rust toolchain and a C compiler (for building from source)

Documentation#

Tutorials

Learning-oriented – Step-by-step lessons to build skills.

Start here if you are new to zodb-json-codec.

Tutorials
How-To Guides

Goal-oriented – Solutions to specific problems.

Use these when you need to accomplish something.

How-to guides
Reference

Information-oriented – Technical specifications and API details.

Consult when you need detailed information.

Reference
Explanation

Understanding-oriented – Architecture, design decisions, and optimization history.

Read to deepen your understanding of how it works.

Explanation

Quick start#

  1. Install zodb-json-codec

  2. Encode and decode your first pickle

  3. Work with ZODB records