blitzjson
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,Promisewithout 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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
593997d806ad39ca5e36ea4415df850b12743ab05a437f9975ea4b336d5d6964
|
|
| MD5 |
eb088f77f49e08b20f26f50e9e81fb6d
|
|
| BLAKE2b-256 |
eebf3cd7b70d8c1c55cbb8d5c208ed29f45763b99b9caa2c4377b8264e8e271f
|
Provenance
The following attestation bundles were made for blitzjson-0.1.0.tar.gz:
Publisher:
build.yml on rroblf01/blitzjson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blitzjson-0.1.0.tar.gz -
Subject digest:
593997d806ad39ca5e36ea4415df850b12743ab05a437f9975ea4b336d5d6964 - Sigstore transparency entry: 2585874517
- Sigstore integration time:
-
Permalink:
rroblf01/blitzjson@bc35495f581c5372a547ff3a7d58102db0a510bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rroblf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@bc35495f581c5372a547ff3a7d58102db0a510bd -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5af218fadc4385ae5ec8eb20e63eeb320f51cccc85799d75e3140033931cfbb0
|
|
| MD5 |
05261fdd8dab1531fac54968541db5b5
|
|
| BLAKE2b-256 |
712389ac67ed3686c0343cce83df440ee8baefc200749363cb37f3880d368a5a
|
Provenance
The following attestation bundles were made for blitzjson-0.1.0-cp310-abi3-win_amd64.whl:
Publisher:
build.yml on rroblf01/blitzjson
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blitzjson-0.1.0-cp310-abi3-win_amd64.whl -
Subject digest:
5af218fadc4385ae5ec8eb20e63eeb320f51cccc85799d75e3140033931cfbb0 - Sigstore transparency entry: 2585874778
- Sigstore integration time:
-
Permalink:
rroblf01/blitzjson@bc35495f581c5372a547ff3a7d58102db0a510bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rroblf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@bc35495f581c5372a547ff3a7d58102db0a510bd -
Trigger Event:
release
-
Statement type:
File details
Details for the file blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 277.7 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff8a43694a406694c6dcf8ac943dbfd8aedc95fb76f1154529c21c205f10e418
|
|
| MD5 |
0d575756463cfe001a9b6ecd5b5b489a
|
|
| BLAKE2b-256 |
67fc5c6094c6c97eb09bb20858fda7a16a3492ed79aaddfacc86fba58f864d82
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blitzjson-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
ff8a43694a406694c6dcf8ac943dbfd8aedc95fb76f1154529c21c205f10e418 - Sigstore transparency entry: 2585874598
- Sigstore integration time:
-
Permalink:
rroblf01/blitzjson@bc35495f581c5372a547ff3a7d58102db0a510bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rroblf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@bc35495f581c5372a547ff3a7d58102db0a510bd -
Trigger Event:
release
-
Statement type:
File details
Details for the file blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 259.9 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa3b3d766905987f55c073d68b4ade59ea55b85d2a0f72880262c5727d704972
|
|
| MD5 |
0cdbe4fd3358130325cf68dcf6de58c3
|
|
| BLAKE2b-256 |
23eeb97d3014a335cd6ac9b0d04f031ae7ba8df886e1de6125092b67256f4ec6
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
blitzjson-0.1.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
aa3b3d766905987f55c073d68b4ade59ea55b85d2a0f72880262c5727d704972 - Sigstore transparency entry: 2585874890
- Sigstore integration time:
-
Permalink:
rroblf01/blitzjson@bc35495f581c5372a547ff3a7d58102db0a510bd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/rroblf01
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@bc35495f581c5372a547ff3a7d58102db0a510bd -
Trigger Event:
release
-
Statement type: