Rust acceleration core for marshmallow serialization, installed as a separate, opt-in package.
Project description
marshmallow_core
A Rust acceleration core for marshmallow,
shipped as a separate, opt-in package. Install it next to stock marshmallow
and activate it explicitly — it replaces marshmallow's per-object
_serialize / _deserialize loops with a PyO3 extension while producing
identical results.
pip install marshmallow marshmallow_core
import marshmallow as ma
import marshmallow_core
marshmallow_core.install() # patch marshmallow.Schema in this process
class Person(ma.Schema):
name = ma.fields.String()
age = ma.fields.Integer()
Person().load({"name": "ann", "age": "30"}) # accelerated
Person().dump({"name": "ann", "age": 30}) # accelerated
marshmallow_core.uninstall() # restore the stock pure-Python methods
How it works
install()monkey-patchesSchema._serializeandSchema._do_load. Each bound schema is compiled once (cached on the instance) into a recursive payload describing every field as either native (run entirely in Rust) or a callback (defers to the PythonFieldmethod). Anything not modelled natively stays a callback, so output is behaviour-identical.- The load core handles only the happy path: the instant it hits any
error/edge case it raises an internal
AccelFallbackand marshmallow re-runs the unchanged pure-Python load, so every error message and value matches exactly. The dump core has no fallback, so each native dump element is provably identical toField._serialize. dumpsis fused: it writes JSON bytes directly in Rust, skipping the intermediate Python dict and thejson.dumpspass, byte-for-byte identical tojson.dumps(schema.dump(obj)). It activates for hook-free schemas using the stdlibjsonrender module with no extrajsonkwargs, and falls back todump+json.dumpsfor anything it can't reproduce exactly. (loadsis already accelerated through the patched load path; a Rust JSON parser was prototyped but did not beat CPython's Cjson.loads, so it was not shipped.)- Acceleration is strictly a speedup. Set
MARSHMALLOW_NO_ACCEL=1(or hit a protocol-version mismatch between the Python and Rust halves) and the core becomes a no-op even afterinstall().
Scope / limitations
install() accelerates dump for all compilable schemas, and load for most
schemas — including those with pre_load / post_load / validates /
validates_schema hooks: the core runs the per-field deserialize step while
those hooks run in Python around it (mirroring marshmallow's own _do_load
split). Recognized field validators (Range / Length / OneOf) run natively;
any other validator, or field-level pre_load / post_load, keeps that field
on the callback path. unknown=INCLUDE, collection/dotted partial, and dotted
attribute writes are all accelerated. Custom dict_class / get_attribute,
self-referential schemas, custom strptime temporal formats, and callable
defaults always fall back to pure Python.
Development
Requires cargo (rustup) and maturin.
# build + install the extension into the current venv
uvx maturin develop --release
# run the tests (needs marshmallow + pytest installed)
pytest
# force the pure-Python path
MARSHMALLOW_NO_ACCEL=1 pytest
tests/test_equivalence.py asserts that dump/load produce identical output
and errors with the core active vs. forced onto pure Python, across scalars,
nested/list/enum/temporal/UUID fields, partial=True, and error inputs.
Benchmarking
The performance/ directory (not shipped in wheels) measures the core against
stock marshmallow through the public install() / uninstall() API. Run it from
the repo root with the compiled extension importable (uvx maturin develop --release first, or point PYTHONPATH at the repo while the wheel is installed):
# stock-vs-core table for dump / load / dumps / loads on four schema shapes
python -m performance.benchmark # all cases
python -m performance.benchmark --number 20000 --only flat,list
# coverage probe: per-field native vs callback for each schema shape
python -m performance.analyze_paths
benchmark.py reports per-call microseconds for stock and core plus the speedup
ratio, across flat-scalar, nested, list-heavy, and validator-heavy schemas.
analyze_paths.py inspects the compiled payload and shows which fields run
native in Rust vs. fall back to a Python callback — it tells you exactly where a
real schema still defers to pure Python.
Releasing
CI (.github/workflows/ci.yml) builds the wheel and runs the suite against
stock marshmallow on Python 3.10–3.13, both with the core active and with
MARSHMALLOW_NO_ACCEL=1. Publishing (.github/workflows/release.yml) builds
abi3 wheels + sdist for Linux/macOS/Windows on a v* tag and uploads them to
PyPI via trusted publishing. Before
the first release, configure the PyPI trusted publisher for this repo and create
a pypi GitHub Environment, then push a tag (e.g. git tag v0.1.0 && git push --tags).
License
MIT
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
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 marshmallow_core-0.1.0.tar.gz.
File metadata
- Download URL: marshmallow_core-0.1.0.tar.gz
- Upload date:
- Size: 46.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96ea1a07a3a22760ae2b5a20d647cc218d0b8604fd8d977eca03e045c4084d9e
|
|
| MD5 |
05521767cabe2101ab7b6213cb3d1f0c
|
|
| BLAKE2b-256 |
5d6408cd215eb6443a81597edaf7bcd75509dfed0400d3847beb66dd15d0b062
|
Provenance
The following attestation bundles were made for marshmallow_core-0.1.0.tar.gz:
Publisher:
release.yml on gunlinux/marshmallow_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marshmallow_core-0.1.0.tar.gz -
Subject digest:
96ea1a07a3a22760ae2b5a20d647cc218d0b8604fd8d977eca03e045c4084d9e - Sigstore transparency entry: 1763057609
- Sigstore integration time:
-
Permalink:
gunlinux/marshmallow_core@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gunlinux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Trigger Event:
push
-
Statement type:
File details
Details for the file marshmallow_core-0.1.0-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: marshmallow_core-0.1.0-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 186.7 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0931739181a74c6318593840fd3e6dba968cbc9073c9dc72aaae498be4c19ec
|
|
| MD5 |
9de3c0afc501ec78b608404ee3c1978c
|
|
| BLAKE2b-256 |
47aa72786f382e11aec4e9950b14d0bed7a36eda0a0f09ae5c736816bb6d94cb
|
Provenance
The following attestation bundles were made for marshmallow_core-0.1.0-cp310-abi3-win_amd64.whl:
Publisher:
release.yml on gunlinux/marshmallow_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marshmallow_core-0.1.0-cp310-abi3-win_amd64.whl -
Subject digest:
c0931739181a74c6318593840fd3e6dba968cbc9073c9dc72aaae498be4c19ec - Sigstore transparency entry: 1763058167
- Sigstore integration time:
-
Permalink:
gunlinux/marshmallow_core@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gunlinux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Trigger Event:
push
-
Statement type:
File details
Details for the file marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 319.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff459935ad7f454732ca9a2f9159299eaed04f0cab73086d5c622cb3d9f2ff58
|
|
| MD5 |
f1354d93dd37ef99941c166190dfaa46
|
|
| BLAKE2b-256 |
a5578b4a84d4ee8663c75b10319b2526716816464452010122c75172e548b39b
|
Provenance
The following attestation bundles were made for marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on gunlinux/marshmallow_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
ff459935ad7f454732ca9a2f9159299eaed04f0cab73086d5c622cb3d9f2ff58 - Sigstore transparency entry: 1763058014
- Sigstore integration time:
-
Permalink:
gunlinux/marshmallow_core@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gunlinux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Trigger Event:
push
-
Statement type:
File details
Details for the file marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 319.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0daf88de3254583eef10365480e5e5c68ff82588b69dc4d71519cf0fd8a5150
|
|
| MD5 |
80b9d87750349efc9ede53b76330e5f6
|
|
| BLAKE2b-256 |
cde314a70f0198ef6768e8b97cb772a70115d40e55180b7af942e2043e6d1cfc
|
Provenance
The following attestation bundles were made for marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on gunlinux/marshmallow_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marshmallow_core-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
f0daf88de3254583eef10365480e5e5c68ff82588b69dc4d71519cf0fd8a5150 - Sigstore transparency entry: 1763057886
- Sigstore integration time:
-
Permalink:
gunlinux/marshmallow_core@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gunlinux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Trigger Event:
push
-
Statement type:
File details
Details for the file marshmallow_core-0.1.0-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: marshmallow_core-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 288.9 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27db5640e6cc4544130a7fd738ac860034566587b78c5515ad90fd04f4a0c24c
|
|
| MD5 |
cff1f9e3a1ce73a8d6753f467882d503
|
|
| BLAKE2b-256 |
aaea3fb8453e1fb784564d103eebd5bfc5a5bbecea9f6b6fdc1861e8c6d4374b
|
Provenance
The following attestation bundles were made for marshmallow_core-0.1.0-cp310-abi3-macosx_11_0_arm64.whl:
Publisher:
release.yml on gunlinux/marshmallow_core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
marshmallow_core-0.1.0-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
27db5640e6cc4544130a7fd738ac860034566587b78c5515ad90fd04f4a0c24c - Sigstore transparency entry: 1763057741
- Sigstore integration time:
-
Permalink:
gunlinux/marshmallow_core@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gunlinux
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@bfac0699922dc4ad4e0bd363a2f822d884619a71 -
Trigger Event:
push
-
Statement type: