Тёмный

Liked Pydantic? You'll LOVE Msgspec 

Carberra
Подписаться 19 тыс.
Просмотров 11 тыс.
50% 1

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

Опубликовано:

 

28 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
Просмотров 21 тыс.
HTMX Sucks
25:16
Просмотров 112 тыс.
Угадай МОБА 1 🥵 | WICSUR #shorts
01:00
Просмотров 2,6 млн
Python's contextlib is a HIDDEN GEM
14:55
Просмотров 10 тыс.
*Next-door 10x Software Engineer* [FULL]
4:50
Просмотров 417 тыс.
Errors as Values are the Future
7:19
Просмотров 31 тыс.
I've been using Redis wrong this whole time...
20:53
Просмотров 344 тыс.
Just Use Pydantic
8:11
Просмотров 22 тыс.
7 Years of Software Engineering Advice in 18 Minutes
18:32