Skip to content

Instantly share code, notes, and snippets.

View aprilahijriyan's full-sized avatar
🐼
🐍 Python Developer

Aprila Hijriyan aprilahijriyan

🐼
🐍 Python Developer
  • Indonesia, Garut - Jawa Barat
  • 18:56 (UTC +07:00)
View GitHub Profile
@jcrist
jcrist / bench.py
Last active January 27, 2025 21:01
A quick benchmark comparing msgspec (https://github.com/jcrist/msgspec), pydantic v1, and pydantic v2
"""A quick benchmark comparing the performance of:
- msgspec: https://github.com/jcrist/msgspec
- pydantic V1: https://docs.pydantic.dev/1.10/
- pydantic V2: https://docs.pydantic.dev/dev-v2/
The benchmark is modified from the one in the msgspec repo here:
https://github.com/jcrist/msgspec/blob/main/benchmarks/bench_validation.py
I make no claims that it's illustrative of all use cases. I wrote this up
@kmatarese
kmatarese / pydantic_from_marshmallow.py
Last active January 23, 2024 06:48
Hack to convert marshmallow schemas to pydantic models
"""WARNING: not thoroughly tested and does not support full translation
between the two libraries.
Uses a pydantic root_validator to init the marshmallow schema. It attempts
to map marshmallow field types to pydantic field types as well, but not all
field types are supported.
You can either use the pydantic_from_marshmallow function that does all of
the above or just subclass MarshmallowModel and manually define your pydantic
fields/types/etc.