Skip to main content

Rust/PyO3 accelerator for marshmallow 4.x: native Schema.dump/load with transparent fallback to marshmallow.

Project description

pulse-marshmallow

A Rust/PyO3 accelerator for marshmallow 4.x — a native Schema.dump/Schema.load that is iso-functional with marshmallow, with transparent fallback to marshmallow for anything outside its fast path. marshmallow is structurally "pydantic v1 in pure Python" (per-field interpreted dispatch) and has no native core; this is a separate package that depends on marshmallow and delegates back to it — so it never diverges, by construction.

pip install pulse-marshmallow
# was:  from marshmallow import Schema, fields
from pulse_marshmallow import Schema, fields

class UserSchema(Schema):
    id   = fields.Int(required=True)
    name = fields.Str(validate=validate.Length(max=64))
    tags = fields.List(fields.Str())
    addr = fields.Nested(AddressSchema)

s = UserSchema()           # compiled once
s.dump(obj)                # native serialization
s.load(payload)            # native validation + deserialization; .errors tree identical to marshmallow

Only the import changes. dump/dumps/load/loads/validate, ValidationError, the .errors tree, hooks, fields and validators all work unchanged.

Performance

marshmallow's dump/load is interpreted per-field dispatch (field×object), spending ~88 % of its time in Python machinery (and ~0 % in re on the common path). pulse-marshmallow compiles the schema once into a Rust plan and iterates natively.

Drift-immune A/B (median per call), pre-built schema, realistic schema (7 fields incl. a nested dict and a list), CPython 3.11, Apple Silicon:

path marshmallow pulse (native) speedup
load (validation + error tree) ~13 µs ~1.5 µs ~×8-9
dump (serialization) ~5 µs ~0.8 µs ~×4-6

load carries the bigger win (validation dispatch + error accumulation); dump is leaner. Validators are executed via Python (the And(*validators) object), so message parity is exact at no measurable cost (the cost is the dispatch, not the comparison).

What's covered natively (and what falls back)

Native fields: Str, Int (+as_string/strict), Float (+as_string/allow_nan), Bool, Raw, Nested, List, Dict (keys/values), and Email/Url (coercion identical to String, regex run via Python). Options: data_key, attribute, required, allow_none, load_default (const), load_only/dump_only, many, unknown (RAISE/EXCLUDE/INCLUDE). Validators (Range/Length/OneOf/ custom/Regexp) run via Python → exact messages, no restriction.

Everything else is transparently delegated to marshmallow: dump hooks (@pre_dump/@post_dump) disable native dump; load hooks (@pre_load/@post_load/@validates/@validates_schema) disable native load; C-bound/computed fields (DateTime/UUID/Decimal/Enum/Method/Function), dump_default, callable load_default, dotted attribute, Nested only/exclude, custom Bool truthy/falsy, explicit partial/unknown, custom dict_class/get_attribute. Note: native acceleration targets marshmallow 4.x; on 3.x it transparently falls back (correct, no speedup).

A key point on coverage: @post_load (the idiomatic "load → build an object") is load-only, so a schema that uses it still gets native dump. Across a sample of real OSS repos, only ~12 % of schemas carry a load hook — hooks are not the limiting factor; the field whitelist is.

Iso-functionality

Proven by a typed differential oracle comparing dump AND load (the result, or the full ValidationError.messages tree) against marshmallow, on a curated corpus plus adversarial fuzzing of random schemas and payloads — including the bool/coercion subtleties, the nested/list/dict error trees, unknown policies, and the @post_load-still-allows-native-dump lever. Error messages and truthy/ falsy sets are read from the field, so custom messages work. The pure-marshmallow fallback path is verified iso too (PULSE_FORCE_FALLBACK=1).

Wheels

abi3 wheels (Python ≥ 3.11) for Linux (x86_64/aarch64, manylinux + musllinux), macOS (Apple Silicon), and Windows; sdist elsewhere (builds the Rust core via maturin).

License

MIT (same as marshmallow).

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

pulse_marshmallow-0.1.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distributions

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

pulse_marshmallow-0.1.0-cp311-abi3-win_amd64.whl (163.9 kB view details)

Uploaded CPython 3.11+Windows x86-64

pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (276.0 kB view details)

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

pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (272.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

pulse_marshmallow-0.1.0-cp311-abi3-macosx_11_0_arm64.whl (254.3 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pulse_marshmallow-0.1.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pulse_marshmallow-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7e0bcce2aa97e8e62a6a82f0ea3547bee1c95eb403cbba117714843dae31679e
MD5 73445ef214289f89adad24d4fcda1e4d
BLAKE2b-256 9cedc686ee68477c5b4f2a19e54884db67646d2f4d9c36830ce0118491113964

See more details on using hashes here.

Provenance

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

Publisher: release.yml on AstekGroup/pulse-marshmallow

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

File details

Details for the file pulse_marshmallow-0.1.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pulse_marshmallow-0.1.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 30717a62754031a837b779fadb23be0ac793dd4f4459aaba2632f63b8fb061e1
MD5 81dbebfd4b94598cb85d407c9af6c039
BLAKE2b-256 00887b68915299e3d1ce81433be565356442de6eac460e971a9860f77cd19920

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_marshmallow-0.1.0-cp311-abi3-win_amd64.whl:

Publisher: release.yml on AstekGroup/pulse-marshmallow

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

File details

Details for the file pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f590314b1b5fa3a1ea704c13eec8ed849529240318b60c1ece776247ee6fb31
MD5 2b9dedd31272a9047faee0ed4b5a2106
BLAKE2b-256 931e4ca3470dea29ccf972f692570cb7348cb02ae9e4ed290eeaf5e19d35156f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on AstekGroup/pulse-marshmallow

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

File details

Details for the file pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4b8f84af556741f7f5bf6e013b0431385d38bc9d0a46811f7ddf1799bd4a67da
MD5 becc43904bc1af205fee48bc01b497c0
BLAKE2b-256 768a0b5d36f56e0bef35ca8f1ea10e6cc1ba5c15ee5dd93be2a99814c66735e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_marshmallow-0.1.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on AstekGroup/pulse-marshmallow

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

File details

Details for the file pulse_marshmallow-0.1.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pulse_marshmallow-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55ffcde21827e20750b317ba094aa4b883ce128616fa2243b595ce89230c4a7c
MD5 6b2cc98db915c9e3aab8dfa4bea24641
BLAKE2b-256 fc7bae356698ba61cb4d3c735e734046c4bfc1d1f9e9205fcd9fb74deba97aa5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pulse_marshmallow-0.1.0-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on AstekGroup/pulse-marshmallow

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

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