Bake marshmallow schemas based on dataclasses
Project description
marshmallow-recipe
The main goal of this opinionated library is to simplify migration from marshmallow2 to marshmallow3. Also, it helps with:
- Stop writing marshmallow schema completely: it generates them from dataclass.
- Using different naming cases(camel and capital camel cases are supported).
- Utilizing best practises on fields configuration.
import dataclasses
import marshmallow_recipe as mr
import uuid
@dataclasses.dataclass(frozen=True)
class Transaction:
id: uuid.UUID
created_at: datetime.datetime
processed_at: datetime.datetime | None
amount: decimal.Decimal
transaction = Transaction(
id=uuid.uuid4(),
created_at=datetime.datetime.utcnow(),
processed_at=None,
amount=decimal.Decimal(42),
)
# dumps the transaction to a dict
raw = mr.dump(transaction)
# loads a transaction from the dict
mr.load(Transaction, raw)
# provides a generated marshmallow schema for dataclass
mr.schema(Transaction)
v0.0.9(2022-04-26)
v0.0.8(2022-03-26)
v0.0.7(2022-03-20)
v0.0.6(2022-03-20)
v0.0.5(2022-03-01)
- Validate before dump for marshmallow3
- Move many to schema
- Fix default naming case
- Fix unhashable type: 'set' error
v0.0.4(2022-02-21)
- Support decimal field
- Support metadata
- Support int field
- Support float field
- Support uuid field
- Support list and dict
- Support marshmallow3
- Support datetime and date
- Unify datetime.tzinfo behaviour
v0.0.3 (2022-02-14)
v0.0.2 (2022-02-13)
v0.0.1 (2022-02-13)
- A first version
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
File details
Details for the file marshmallow-recipe-0.0.9.tar.gz
.
File metadata
- Download URL: marshmallow-recipe-0.0.9.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a85a75235f218eb0156b3c9cdc433b30879484964a8dcdb6c820bc5d7577234 |
|
MD5 | 705aa4938b947ddca2902c3544dec9df |
|
BLAKE2b-256 | 02698b7bba1c82742b39afe116d18d305bc96a3c20f7dd8e38772ca92cbbbfe2 |
File details
Details for the file marshmallow_recipe-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: marshmallow_recipe-0.0.9-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0995ae99e9450d118b84579cee2c5d8a92db1c3c65701a013c87b143899e4260 |
|
MD5 | bd7dc96812429bd70b4af49668f71f2a |
|
BLAKE2b-256 | 177616e0aa5d8bff6b112a2930832daf49518d8ad433ee84fbcec08c0df822f2 |