Skip to main content

blitzjson

License: MIT

Drop-in replacement for Python's json module with native Django type support. Built with Rust via PyO3 for maximum performance.

Features

  • Drop-in replacement: Same API as json.dumps(), json.loads(), etc.
  • Native Django types: Handles datetime, date, time, timedelta, UUID, Decimal, QuerySet, Model, Promise without custom encoders
  • Rust-powered: Direct serialization to JSON buffer via CPython FFI, no intermediate Python objects
  • Zero dependencies: No runtime Python dependencies required
  • Full json API: ensure_ascii, indent, sort_keys, allow_nan, default (recursive)
  • Streaming: stream_dump_queryset() for memory-efficient large QuerySet serialization
  • Django integration: BlitzJsonResponse, BlitzJSONEncoder, install() monkey-patch

Installation

pip install blitzjson

Quick Start

# Before
import json
from datetime import datetime

json.dumps({"created": datetime.now()})  # TypeError!

# After
import blitzjson as json

json.dumps({"created": datetime.now()})  # Works!

Monkey-patching (try before you commit)

If you want to test blitzjson in your existing project without changing any import json statements, use the install() function to monkey-patch Python's built-in json module:

# In your settings.py or at the top of manage.py
import blitzjson
blitzjson.install()

# Now ALL code that uses `import json` will use blitzjson instead
import json
json.dumps({"created": datetime.now()})  # Works! No TypeError!

Or test it interactively:

>>> import blitzjson
>>> blitzjson.install()
>>> import json
>>> json.dumps({"created": datetime.now(), "uuid": uuid4()})
'{"created": "2024-01-15T10:30:45+00:00", "uuid": "550e8400-e29b-41d4-a716-446655440000"}'

>>> # Revert when done testing
>>> blitzjson.uninstall()

Supported Types

Python Type JSON Output Example
datetime ISO 8601 string "2024-01-15T10:30:45Z"
date ISO date string "2024-01-15"
time ISO time string "10:30:45"
timedelta ISO 8601 duration "P1DT2H3M4S"
UUID Hyphenated string "550e8400-e29b-41d4-a716-446655440000"
Decimal String (precision-safe) "123.456789012345678901"
bytes Base64 string "aGVsbG8="
set/frozenset Array [1, 2, 3]
enum Value "value"
dataclass Object {"field": "value"}

Django-Specific

Django Type JSON Output
QuerySet Array of model dicts
Model Dict of field values
Promise (lazy strings) String

API

dumps(obj, **kwargs)

import blitzjson as json

# Standard usage
json.dumps({"key": "value"})

# With Django types
json.dumps({"created": datetime.now(), "uuid": uuid4()})

loads(s, **kwargs)

obj = json.loads('{"key": "value"}')

# With object_hook
obj = json.loads('{"key": "value"}', object_hook=lambda d: {k.upper(): v for k, v in d.items()})

dump(obj, fp, **kwargs) / load(fp, **kwargs)

File-based serialization/deserialization.

dumpb(obj, pretty=False)

Serialize to bytes (faster than dumps for network responses).

dump_queryset(queryset) / dump_queryset_bytes(queryset)

Optimized serialization for Django QuerySets.

Benchmarks

vs json + DjangoJSONEncoder (CPython 3.14, Linux x86_64, consumer hardware):

Note: Benchmarks run on consumer hardware (AMD Ryzen 9 7900X). CI runners (Intel Xeon server CPUs) may show different results due to lower single-thread performance. For stable benchmarks, run locally with uv run python benchmarks/bench_serialization.py.

dumps

Benchmark                           json+DJE    blitzjson    Speedup
------------------------------------------------------------------------
Simple dict (4 fields)                 2.5µs        0.8µs      3.0x
Nested dict (deep)                     5.4µs        1.8µs      3.0x
Large list (1000 items)              752.1µs      193.2µs      3.9x
String-heavy dict (20 keys)            4.8µs        1.5µs      3.1x
Datetime dict                         10.3µs        3.6µs      2.8x
UUID dict                              7.3µs        3.9µs      1.9x
Decimal dict                           4.4µs        1.6µs      2.7x
Mixed dict (all types)                 7.3µs        2.8µs      2.6x

loads

Benchmark                               json    blitzjson    Speedup
------------------------------------------------------------------------
Simple dict (4 fields)                 1.5µs        0.8µs      2.0x
Nested dict (deep)                     5.1µs        3.2µs      1.6x
Large list (1000 items)              716.0µs      421.2µs      1.7x
String-heavy dict (20 keys)            4.3µs        2.7µs      1.6x

Django Response

Benchmark                             JsonResponse      BlitzJson    Speedup
------------------------------------------------------------------------
API response (50 users)                 44.9µs         19.6µs      2.3x

Requirements

  • Python 3.10+
  • No Rust installation required (pre-built wheels)

License

MIT - Ricardo Robles Fernández

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blitzjson-0.1.0.tar.gz (39.7 kB view details)

Uploaded Source

Built Distributions

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

blitzjson-0.1.0-cp310-abi3-win_amd64.whl (190.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (277.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (259.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file blitzjson-0.1.0.tar.gz.

File metadata

  • Download URL: blitzjson-0.1.0.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for blitzjson-0.1.0.tar.gz
Algorithm Hash digest
SHA256 593997d806ad39ca5e36ea4415df850b12743ab05a437f9975ea4b336d5d6964
MD5 eb088f77f49e08b20f26f50e9e81fb6d
BLAKE2b-256 eebf3cd7b70d8c1c55cbb8d5c208ed29f45763b99b9caa2c4377b8264e8e271f

See more details on using hashes here.

Provenance

The following attestation bundles were made for blitzjson-0.1.0.tar.gz:

Publisher: build.yml on rroblf01/blitzjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blitzjson-0.1.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: blitzjson-0.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 190.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for blitzjson-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5af218fadc4385ae5ec8eb20e63eeb320f51cccc85799d75e3140033931cfbb0
MD5 05261fdd8dab1531fac54968541db5b5
BLAKE2b-256 712389ac67ed3686c0343cce83df440ee8baefc200749363cb37f3880d368a5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for blitzjson-0.1.0-cp310-abi3-win_amd64.whl:

Publisher: build.yml on rroblf01/blitzjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff8a43694a406694c6dcf8ac943dbfd8aedc95fb76f1154529c21c205f10e418
MD5 0d575756463cfe001a9b6ecd5b5b489a
BLAKE2b-256 67fc5c6094c6c97eb09bb20858fda7a16a3492ed79aaddfacc86fba58f864d82

See more details on using hashes here.

Provenance

The following attestation bundles were made for blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on rroblf01/blitzjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa3b3d766905987f55c073d68b4ade59ea55b85d2a0f72880262c5727d704972
MD5 0cdbe4fd3358130325cf68dcf6de58c3
BLAKE2b-256 23eeb97d3014a335cd6ac9b0d04f031ae7ba8df886e1de6125092b67256f4ec6

See more details on using hashes here.

Provenance

The following attestation bundles were made for blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: build.yml on rroblf01/blitzjson

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

4 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page