Dataclasses is now a relative new feature for python and claims to replace pydantic. Is FastAPI possible to use Python dataclasses in the future?
Maybe I don鈥檛 know any features of dataclasses, fastapi and pydantic, so maybe this question is a little dumb.
Dataclasses is just a cleaner alternative to regular Python class. The key point is having less boilerplate code like def __init__(self, ...) and having type annotation. (At least that's how I see it.)
Pydantic, in the context of FastAPI at least, is mainly for data validation and/or serialization purposes. I think it also plays a part in generating the OpenAPI JSON for documentation.
So as long as dataclassess is not providing the validation functionality, it cannot replace Pydantic. You can, however, use it to define your data models and map them to the database if the ORM allows.
Looks like pydantic does support them in some way: https://pydantic-docs.helpmanual.io/usage/dataclasses/
More in-depth discussion here: https://github.com/samuelcolvin/pydantic/issues/710
Thanks for answers. I close issue.
Thanks for the help here everyone! :clap: :bow:
Thanks for reporting back and closing the issue :+1:
Most helpful comment
Looks like pydantic does support them in some way: https://pydantic-docs.helpmanual.io/usage/dataclasses/
More in-depth discussion here: https://github.com/samuelcolvin/pydantic/issues/710