Some extra sweets for marshmallow.
Project description
Some extra sweets for marshmallow.
Examples
Use annotations for schema description.
from jam import Schema
class Bar(Schema):
baz: str
class Foo(Schema):
bar: Bar
foo: Foo = Foo().load({"bar": {"baz": "quux"}})
assert foo.bar.baz == "quux"
When annotations not enough
class Foo(Schema):
bar: str = fields.Email()
Mapping rules
Basic Types
annotation |
marshmallow field |
---|---|
str |
fields.String |
float |
fields.Float |
bool |
fields.Boolean |
int |
fields.Integer |
uuid.UUID |
fields.UUID |
decimal.Decimal |
fields.Decimal |
dt.datetime |
fields.DateTime |
dt.time |
fields.Time |
dt.date |
fields.Date |
dt.timedelta |
fields.TimeDelta |
All fields will be required for make it optional use typing.Optional[X]
Many
annotation |
marshmallow field |
---|---|
list |
fields.Raw(many=True) |
typing.List[float] |
fields.List(fields.Float()) |
Nested
annotation |
marshmallow field |
---|---|
NestedSchema |
fields.Nested(NestedSchema, required=True) |
typing.Optional[NestedSchema] |
fields.Nested(NestedSchema, required=True) |
typing.List[NestedSchema] |
fields.Nested(NestedSchema, required=True, many=True) |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for marshmallow_jam-1.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc92a46cd7d5b01f4c30377685118699e3ffe901760354cd5c9d7d6d7f53688a |
|
MD5 | f93652d04953c754896822cae3363242 |
|
BLAKE2b-256 | 6fce7855805e7f81bd3726fe719a1fbdbd4c7aa75629aa5e9ff62ca41aebce47 |