pydantic-marshmallow 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pydantic_marshmallow/__init__.py +79 -0
- pydantic_marshmallow/bridge.py +1187 -0
- pydantic_marshmallow/errors.py +154 -0
- pydantic_marshmallow/field_conversion.py +137 -0
- pydantic_marshmallow/py.typed +2 -0
- pydantic_marshmallow/type_mapping.py +138 -0
- pydantic_marshmallow/validators.py +207 -0
- pydantic_marshmallow-1.0.0.dist-info/METADATA +367 -0
- pydantic_marshmallow-1.0.0.dist-info/RECORD +12 -0
- pydantic_marshmallow-1.0.0.dist-info/WHEEL +5 -0
- pydantic_marshmallow-1.0.0.dist-info/licenses/LICENSE +21 -0
- pydantic_marshmallow-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pydantic-marshmallow: Bridge Pydantic's power with Marshmallow's ecosystem.
|
|
3
|
+
|
|
4
|
+
This package provides seamless integration between Pydantic models and Marshmallow
|
|
5
|
+
schemas, enabling you to use Pydantic's powerful validation while maintaining
|
|
6
|
+
compatibility with the Marshmallow ecosystem (Flask-Marshmallow, webargs, apispec, etc.).
|
|
7
|
+
|
|
8
|
+
Core Components:
|
|
9
|
+
PydanticSchema: A Marshmallow schema backed by a Pydantic model
|
|
10
|
+
HybridModel: A Pydantic model with built-in Marshmallow support
|
|
11
|
+
schema_for: Factory function to create schemas from models
|
|
12
|
+
pydantic_schema: Decorator to add .Schema attribute to models
|
|
13
|
+
BridgeValidationError: Exception with valid_data tracking
|
|
14
|
+
|
|
15
|
+
Basic Usage:
|
|
16
|
+
>>> from pydantic import BaseModel, EmailStr
|
|
17
|
+
>>> from pydantic_marshmallow import PydanticSchema
|
|
18
|
+
>>>
|
|
19
|
+
>>> class User(BaseModel):
|
|
20
|
+
... name: str
|
|
21
|
+
... email: EmailStr
|
|
22
|
+
>>>
|
|
23
|
+
>>> class UserSchema(PydanticSchema[User]):
|
|
24
|
+
... class Meta:
|
|
25
|
+
... model = User
|
|
26
|
+
>>>
|
|
27
|
+
>>> schema = UserSchema()
|
|
28
|
+
>>> user = schema.load({"name": "Alice", "email": "alice@example.com"})
|
|
29
|
+
>>> print(user.name) # "Alice" - it's a Pydantic User instance!
|
|
30
|
+
|
|
31
|
+
With Decorator:
|
|
32
|
+
>>> from pydantic_marshmallow import pydantic_schema
|
|
33
|
+
>>>
|
|
34
|
+
>>> @pydantic_schema
|
|
35
|
+
... class User(BaseModel):
|
|
36
|
+
... name: str
|
|
37
|
+
... email: EmailStr
|
|
38
|
+
>>>
|
|
39
|
+
>>> user = User.Schema().load({"name": "Alice", "email": "alice@example.com"})
|
|
40
|
+
|
|
41
|
+
Features:
|
|
42
|
+
- Full Pydantic validation, coercion, and error messages
|
|
43
|
+
- Marshmallow hooks: @pre_load, @post_load, @pre_dump, @post_dump
|
|
44
|
+
- Marshmallow validators: @validates, @validates_schema
|
|
45
|
+
- Partial loading: partial=True or partial=('field1', 'field2')
|
|
46
|
+
- Unknown field handling: unknown=RAISE/EXCLUDE/INCLUDE
|
|
47
|
+
- Field filtering: only=, exclude=, load_only=, dump_only=
|
|
48
|
+
- Pydantic @computed_field support in dumps
|
|
49
|
+
- Works with Flask-Marshmallow, webargs, apispec, and more
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
# Re-export Marshmallow's validators - these work with PydanticSchema
|
|
53
|
+
# Also export hooks for convenience
|
|
54
|
+
from marshmallow import EXCLUDE, INCLUDE, RAISE, post_dump, post_load, pre_dump, pre_load, validates, validates_schema
|
|
55
|
+
|
|
56
|
+
from .bridge import HybridModel, PydanticSchema, pydantic_schema, schema_for
|
|
57
|
+
from .errors import BridgeValidationError
|
|
58
|
+
|
|
59
|
+
# Note: We re-export Marshmallow's @validates and @validates_schema above.
|
|
60
|
+
# Our bridge's _do_load calls Marshmallow's native validator system,
|
|
61
|
+
# so `from marshmallow import validates` works correctly with PydanticSchema.
|
|
62
|
+
|
|
63
|
+
__version__ = "0.1.0"
|
|
64
|
+
__all__ = [
|
|
65
|
+
"EXCLUDE",
|
|
66
|
+
"INCLUDE",
|
|
67
|
+
"RAISE",
|
|
68
|
+
"BridgeValidationError",
|
|
69
|
+
"HybridModel",
|
|
70
|
+
"PydanticSchema",
|
|
71
|
+
"post_dump",
|
|
72
|
+
"post_load",
|
|
73
|
+
"pre_dump",
|
|
74
|
+
"pre_load",
|
|
75
|
+
"pydantic_schema",
|
|
76
|
+
"schema_for",
|
|
77
|
+
"validates",
|
|
78
|
+
"validates_schema",
|
|
79
|
+
]
|