I'm trying to model an API request in Pydantic. I have to model a field called "from". Since "from" is a keyword in python, Pydantic throws an error.
Model
class MyRequest(BaseModel):
foo: str
abc: int
from: int
Error thrown by Pydantic
File "test.py", line 6
from: int
SyntaxError: invalid syntax
Is there to model this "from" field? Changing the parameter name is not an option.
Use an alias:
class MyRequest(BaseModel):
foo: str
abc: int
from_field: int = Field(..., alias='from')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With