Skip to content

Add support for pydantic #26

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

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

igalshilman
Copy link
Contributor

This commit adds an optional support for pydantic models. To use this simply add the pydantic dependency, and annotate a handler with it.

Greeting(BaseModel):
  name: str

@svc.handler()
async def greet(ctx, greeting: Greeting):
  ..

With this, any bad input (validation error) will result with a TerminalError thrown by the serializer.

@igalshilman igalshilman force-pushed the pydantic_support branch 2 times, most recently from 6933f3c to 325274a Compare October 23, 2024 12:24
This commit adds an optional support for pydantic models.
To use this simply add the pydantic dependency, and annotate
a handler with it.

```py

Greeting(BaseModel):
  name: str

@svc.handler()
async def greet(ctx, greeting: Greeting):
  ..
```

With this, any bad input (validation error) will result with a
TerminalError thrown by the serializer.
@igalshilman igalshilman merged commit 946f418 into restatedev:main Oct 23, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant