r/FastAPI • u/anubhavrai85 • Feb 11 '21
Question Project structure for scalable fastapi project.
What would be the project structure for scalable large fast api project? What should I use orm or async postgress library?
4
u/michaelherman Feb 11 '21
You can find a number of large open source projects here: https://github.com/mjhea0/awesome-fastapi#open-source-projects.
As for the database adapter, it depends (as always):
Do you like working directly with SQL or prefer the abstractions that an ORM gives you?
Do you prefer the active record or data mapper style ORM?
Do you want to leverage async capabilities at the database level?
For me, I-
Like the constructs that you get from an ORM.
Prefer the data mapper approach for CRUD apps, but the flexibility of active record for all other apps.
Use psycopg2 for enterprise apps (since it's battle-tested) and https://github.com/encode/databases (with asyncpg) for toy apps.
Examples:
Orator ORM + psycopg2 - https://testdriven.io/blog/fastapi-graphql/
Motor + Mongo - https://testdriven.io/blog/fastapi-mongo/
SQLAlchemy with both asyncpg and psycopg2 - https://testdriven.io/blog/fastapi-crud
1
11
u/Kashyapm94 Feb 11 '21
I found a couple of really good boilerplate structures:
(This is by the developer of Fastapi itself) https://github.com/tiangolo/full-stack-fastapi-postgresql/tree/master/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app
https://github.com/skb1129/fastapi-boilerplate (This is inspired by the first one, but is just for the backend)