feat: add msgspec support #154
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for msgspec
Structtypes in Restate SDK Python handlers, following the same pattern as existing Pydantic support.Closes #146
Accompanying docs PR: restatedev/docs-restate#98
Changes
Core Implementation
python/restate/serde.py- AddedMsgspecJsonSerdeclass and msgspec type detectionpython/restate/handler.py- Added automatic msgspec type detection and serde selection (priority: msgspec → Pydantic → dataclass → JSON)python/restate/discovery.py- Added JSON schema generation for msgspec types usingmsgspec.json.schema()pyproject.toml- Addedmsgspectoserdeoptional dependenciesExample
Added
examples/msgspec_greeter.pydemonstratingmsgspec.Structusage, mirroring the existingpydantic_greeter.pyexample.Testing
Test Script
A standalone test script
Running Tests
Prerequisites:
# Start Restate server podman run --name restate_dev --rm \ -p 8080:8080 -p 9070:9070 -p 5122:5122 \ --add-host=host.docker.internal:host-gateway \ docker.restate.dev/restatedev/restate:1.5.3 --log-format=compactRun the test service:
Register the service:
Test Cases