Fastapi: Using neomodel's data models in place of pydantic

Created on 23 Oct 2020  Â·  4Comments  Â·  Source: tiangolo/fastapi

I am making a fastapi server with neo4j database, and am using the neomodel driver for connecting to the database.
I will have to create 2 seperate models, first in neomodel, second in pydantic (for request body validation and stuff). Is there a way to use the neomodel models in all the places where pydantic models are used in fastapi, if not could anyone point me in a direction to make the development experience as frictionless as possible.

Also, I am open to making a PR (if this is a feature that can be implemented), I'll just need a little guidance because I don't know the fastapi codebase.

BTW, thanks for the amazing library!

question

Most helpful comment

Damn, this is nice. I'd love to be able to do that.
Hope this turns into a feature soon.

Anyways, thanks for your time and help @Kludex ♥
And, thanks for the library @tiangolo 🙌

All 4 comments

I don't think there's space for that on the FastAPI code source. I see it as analogous of what we do when we use SQLAlchemy: create both Pydantic and SQLAlchemy models.

What I've checked is that there's a package called django-neomodel (last commit 2 years ago) that could give you ideas on a possible package called fastapi-neomodel. Similar to what @tiangolo is doing for SQLAlchemy + Pydantic.

Thank you for pointing me in the right direction!

@tiangolo's pydantic-sqlalchemy is the inspiration that I was looking for, the codebase looks relatively simple, to use for making a pydantic-neomodel library, but then it seems like I will lose so many features in pydantic like constraints, because there is limited support for most of them in neomodel (afaik).

Maybe asking for pydantic models support in neomodel is a better approach. Your thoughts?

To be honest, pydantic-sqlalchemy was not the one I was talking about. I was talking about this. It's not available yet, and I don't know if it will, but the idea I was referring is that one.

but then it seems like I will lose so many features in pydantic like constraints, because there is limited support for most of them in neomodel (afaik).

Well, if you want an interface between those two, it seems fair to limit one based on the other.

Maybe asking for pydantic models support in neomodel is a better approach. Your thoughts?

I don't see why not. :+1:

Damn, this is nice. I'd love to be able to do that.
Hope this turns into a feature soon.

Anyways, thanks for your time and help @Kludex ♥
And, thanks for the library @tiangolo 🙌

Was this page helpful?
0 / 5 - 0 ratings