DeepFriedMarshmallow
raw JSON → 1.1.2 verified Fri May 01 auth: no python
A plug-and-play JIT compilation library for Marshmallow schemas that speeds up serialization and deserialization by generating optimized Python code. Current version is 1.1.2, compatible with Python >=3.11 and <4.0.0. The library is actively maintained with a plugin system and built-in inliners for common field types.
pip install deepfriedmarshmallow Common errors
error ModuleNotFoundError: No module named 'deepfriedmarshmallow' ↓
cause Library not installed or installed in a different environment.
fix
Run 'pip install deepfriedmarshmallow'. Ensure you are using Python 3.11+.
error TypeError: jit() missing 1 required positional argument: 'schema_class' ↓
cause Used @jit on a function or incorrectly imported jit.
fix
Use @jit as a class decorator on a Schema subclass, not on a function. Example: @jit class MySchema(Schema): ...
error AttributeError: 'NoneType' object has no attribute 'fields' ↓
cause The @jit decorator was applied to a class that does not inherit from Schema, or the schema was not defined correctly.
fix
Ensure the decorated class inherits from marshmallow.Schema.
error ValidationError: Unknown field. ↓
cause When unknown=RAISE and the input contains a field not defined in the schema, the JIT deserializer may raise a ValidationError.
fix
Handle the exception or set unknown=RAISE explicitly in schema Meta.
Warnings
breaking DeepFriedMarshmallow requires Python >=3.11. Using Python 3.10 or older will cause import errors. ↓
fix Upgrade Python to 3.11 or later.
gotcha The @jit decorator must be applied to a class that inherits from a Marshmallow Schema. Applying it to a standalone class or a non-Schema will not work. ↓
fix Ensure the decorated class is a subclass of marshmallow.Schema.
gotcha The plugin system via DFM_PLUGINS environment variable or entry points may conflict if multiple plugins define the same inliner. The library prefers inliners in a specific order; custom plugins may be overridden. ↓
fix Check plugin documentation and ensure unique inliner definitions.
deprecated In version 1.0.0beta2, the API was unstable. The current stable API (1.1.x) uses the @jit decorator; the older API may have used different symbols. ↓
fix Upgrade to version 1.1.x and use @jit decorator.
Imports
- jit
from deepfriedmarshmallow import jit - JitSerializer
from deepfriedmarshmallow import JitSerializer - JitDeserializer
from deepfriedmarshmallow import JitDeserializer
Quickstart
from marshmallow import Schema, fields
from deepfriedmarshmallow import jit
class UserSchema(Schema):
name = fields.String()
age = fields.Integer()
@jit
class JitUserSchema(UserSchema):
pass
schema = JitUserSchema()
data = {"name": "Alice", "age": 30}
result = schema.load(data)
print(result) # {'name': 'Alice', 'age': 30}
result = schema.dump(result)
print(result) # {'name': 'Alice', 'age': 30}