Liked Pydantic? You'll LOVE Msgspec

  Рет қаралды 10,630

Carberra

Carberra

Күн бұрын

If you've ever needed to work with JSON, TOML, YAML, MessagePack, or even structured data, you'll know how many tools are out there. But what if I told you there was one tool that could do all of those things, complete with a consistent API and with speed as a focus? Well, have I got the treat for you!
00:00 - Intro
00:55 - Working with JSON, TOML, YAML, and MessagePack data [1]
05:38 - Serialisation and deserialisation benchmarks [2-3]
08:56 - Using Pydantic-like structs [4]
13:53 - Struct benchmarks [2-3]
15:16 - Outro
[1] jcristharif.com/msgspec/usage...
[2] jcristharif.com/msgspec/bench...
[3] github.com/Carberra/python-is...
[4] jcristharif.com/msgspec/struc...
-
If you want to see more of me, join my Discord server!
/ discord
I get a lot of people asking, so here's my setup!
• Visual Studio Code: • My Visual Studio Code ...
• Terminal: • Make your terminal loo...
• Desk/recording gear: kit.co/Carberra
• PC build: uk.pcpartpicker.com/list/TmzGYN
Affiliations (I may earn a commission):
• Codecrafters -- 40% off any plan: app.codecrafters.io/join?via=...
• Keeper Password Manager -- 30% off your first year: keeper.io/r/EX4FB1C
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto

Пікірлер: 23
@Mekuso8
@Mekuso8 19 күн бұрын
The "strange" validation that msgspec does is completely on purpose and it fits very well with how I typically use it. Validations at runtime should, IMO, be a last resort as it slows everything down. It's only applied upon decoding, where it's really needed. Everything else is much better handled ahead of time by other libraries like mypy.
@YogenderSinghBhabhoria
@YogenderSinghBhabhoria 16 күн бұрын
Just to clarify the writing modes are binary and text(default), where binary mode returns byte object.
@hansdietrich1496
@hansdietrich1496 21 күн бұрын
Using it for quite a while already. Great piece of software, highly recommended.
@Chiny_w_Pigulce
@Chiny_w_Pigulce 21 күн бұрын
Used it in two projects, it's great
@ChrisHalden007
@ChrisHalden007 20 күн бұрын
Great video. Thanks
@veritas-odium-parit
@veritas-odium-parit 21 күн бұрын
According to my experience from a project it gets additional speedups if you use the provided Decoder or encoder classes.
@Carberra
@Carberra 21 күн бұрын
Which provided classes sorry?
@oliver3880
@oliver3880 21 күн бұрын
@@Carberra you can init a decoder/encoder instance and re-use it. Moreover you can set a decoder/encoder to a specific struct increasing performance even more. dec = msgspec.json.Decoder() dec.decode(msg) say you have some defined msgspec.Struct called ResponseMsg dec = msgspec.json.Decoder(type=ResponseMsg, strict=True) this will decode the json into the ResponseMsg struct and raises an error if the json doesnt comply with your defined struct.
@Carberra
@Carberra 21 күн бұрын
Oooh I see. That's really neat actually!
@dipeshsamrawat7957
@dipeshsamrawat7957 21 күн бұрын
Thanks.
@thekokoserver
@thekokoserver 21 күн бұрын
Esmerald python web framework has this built in with msgspec and is a very fun to work with😊😊
@raccoonteachesyou
@raccoonteachesyou 21 күн бұрын
Hi ! Great video, very concise and interesting ! I'm kind of curious about the validator section tho, you can instantiate Structs with bad values but can't dump them. The only workaround I've seen for this is to implement a __post__init method and writing custom logic, but that's not ideal. Do you know if there's other ways to do this ? Thanks !
@Carberra
@Carberra 21 күн бұрын
As far as I can tell it's the only way, short of contributing something. It does strike me as somewhat of an intentional decision though, which is a bit annoying.
@_rozto
@_rozto 19 күн бұрын
Used it for some time, but the hinting in Struct classes was just not working for me in Pycharm
@machadinhos
@machadinhos 21 күн бұрын
Using with open to write bytes instead of pathlib's Path...you will be in big trouble😬 jk hahaha Great video! Great tool!
@Carberra
@Carberra 21 күн бұрын
Tbh I typically prefer Path's methods haha. Glad you liked the video!
@PetrSzturc
@PetrSzturc 19 күн бұрын
Do you know how to setup loading json into object if the json has nodes names same as keywords? Eg "class". How would you define that struct?
@Carberra
@Carberra 18 күн бұрын
You'd probably need to use aliases.
@RollingcoleW
@RollingcoleW 21 күн бұрын
so was one of the points that pydantic validator is safer?
@Carberra
@Carberra 21 күн бұрын
If you instantiate the class yeah, though if you encode/decode directly, or use a post_init hook, it works similarly.
@RollingcoleW
@RollingcoleW 21 күн бұрын
@@Carberra thanks ok
Pydantic is OP, here's why
18:10
Carberra
Рет қаралды 21 М.
HTMX Sucks
25:16
Theo - t3․gg
Рет қаралды 112 М.
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 35 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 21 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 3,9 МЛН
Python's contextlib is a HIDDEN GEM
14:55
Carberra
Рет қаралды 10 М.
*Next-door 10x Software Engineer* [FULL]
4:50
Programmers are also human
Рет қаралды 417 М.
Errors as Values are the Future
7:19
Isaac Harris-Holt
Рет қаралды 31 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 344 М.
Why Didn't He Get the Job? Let's Find Out! // Code Review
27:25
The Cherno
Рет қаралды 87 М.
Just Use Pydantic
8:11
John Watson Rooney
Рет қаралды 22 М.
7 Years of Software Engineering Advice in 18 Minutes
18:32
Python dataclasses will save you HOURS, also featuring attrs
8:50
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 35 МЛН