-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typed messaging and validation #196
Comments
That's really neat! I was looking at implementing Pydantic in a project a little while ago, and chose not to. It seemed like the API wasn't quite what I was looking for. I was wanting data classes, and confidence that serialization and deserialization were both strict. I'm not quite sure why I concluded that, unfortunately. I knew about the data classes integration with Pydantic, but there was something missing with it that I felt I needed. msgspec looks pretty cool for when you control the data format, but that definitely wasn't part of what I was doing. (I was writing an API wrapper over a JSON API). I know many people have gotten a lot of mileage out of Pydantic. It's a great project. |
Yeah alternatively we've been thinking about using I think this would be a huge boon since we'd get CBS (capability based sec) for free 🏄🏼. The only holdup will be figuring out how |
Oh also another notable project (for a |
Linking to jcrist/msgspec#25 since we'll likely need nested
|
Is there an issue for this. Essentially to do this, we need to:
|
@gc-ss not yet specifically; feel free to make one of course if you have some ideas and/or want to try it out. Also, i think this could be easily wrapped in an external repo for use as well; it doesn't have to be |
@gc-ss wait why would you need this? |
Consider this: class A:
a: int
class B(A):
b: int
class C(A):
c: int
class D:
composes_c: C Now if we wanted auto-gen schema for type D, we don't want to spit out B. Also, it's possible some schema libraries might want schemas to be ordered in a certain way depending on the dependency tree. So you need graphs What do you think? If this makes sense, I can move these into a different repo and send you a link. |
@gc-ss yah, as I was thinking you mean for composed structs/types.
Cool, yeah if you're interested in working on this then for sure. Up to you, I don't have immediate bandwidth for this. |
No longer a problem, we just have to write a prefix framing stream packer; see above. |
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Hmm alternatively to get typing going sooner then later we could just make some Pretty sure we could offer this as an extras dependency as well? |
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Can only really use an encoder currently since there is no streaming api in `msgspec` as of currently. See jcrist/msgspec#27. Not sure if any encoding speedups are currently noticeable especially without any validation going on yet XD. First experiments toward #196
Linking explanation from jcrist/msgspec#25 |
The greasy details are strewn throughout a `msgspec` issue: jcrist/msgspec#140 and specifically this code was mostly written as part of POC example in this comment: jcrist/msgspec#140 (comment) This work obviously pertains to our desire and prep for typed messaging and capabilities aware msg-oriented-protocols in #196, caps sec nods in I added a "wants to have" method to `Context` showing how I think we could offer a pretty neat msg-type-set-as-capability-for-protocol system.
The greasy details are strewn throughout a `msgspec` issue: jcrist/msgspec#140 and specifically this code was mostly written as part of POC example in this comment: jcrist/msgspec#140 (comment) This work obviously pertains to our desire and prep for typed messaging and capabilities aware msg-oriented-protocols in #196, caps sec nods in I added a "wants to have" method to `Context` showing how I think we could offer a pretty neat msg-type-set-as-capability-for-protocol system.
Probably worth noting is dataclass union libs like https://github.com/yukinarit/pyserde |
Hilarious to see a writeup of what we've been doing in this repo for years 😂 the part on ADTs is particularly notable as part of this feature work 🏄🏼 |
I was originally going to make a big post on
pydantic
and how we could offer typed messages using that very very nice project despite there being a couple holdups for integration withmsgpack
.However, it turns out just today an even faster and msgpack specific project was released:
msgspec
🏄🏼It claims to not only be faster then msgpack-python but also supports schema evolution and other niceties
It also has perf bumps when making multiple repeated encode/decode calls which is exactly how we're currently using
msgpack
inside ourChannel
.Overall there looks to be no downside and we'll get typed message semantics fast and free 👍🏼
For reference, I'll leave a bunch of links I'd previously gathered regarding making
pydantic
work withmsgpack
:BaseModel.serialize()
effectively which looks up a serialize method by name (eg. json, msgpack) but isn't really adding any "native feeling" support nor speed gains afaict.TODO
msgpack-python
custom type serializer forpydantic.BaseModel
such that we just implicitly render with.dict()
as pack time and load via `Model(**message)`` at decode time?msgspec
as per the comments in Try msgspec #212trio.SocketStream
using something liketricycle.BufferedReceiveStream
; @oremanj was nice enough to provide usage:msgspec
as an optional dependency if we end up liking it?The text was updated successfully, but these errors were encountered: