r/FastAPI • • 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?

21 Upvotes

4 comments sorted by

11

u/Kashyapm94 Feb 11 '21

I found a couple of really good boilerplate structures:

3

u/[deleted] Feb 11 '21

Thanks for that second link!

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):

  1. Do you like working directly with SQL or prefer the abstractions that an ORM gives you?

  2. Do you prefer the active record or data mapper style ORM?

  3. Do you want to leverage async capabilities at the database level?

For me, I-

  1. Like the constructs that you get from an ORM.

  2. Prefer the data mapper approach for CRUD apps, but the flexibility of active record for all other apps.

  3. Use psycopg2 for enterprise apps (since it's battle-tested) and https://github.com/encode/databases (with asyncpg) for toy apps.

Examples:

  1. Orator ORM + psycopg2 - https://testdriven.io/blog/fastapi-graphql/

  2. Motor + Mongo - https://testdriven.io/blog/fastapi-mongo/

  3. SQLAlchemy with both asyncpg and psycopg2 - https://testdriven.io/blog/fastapi-crud

1

u/potential-waffle Feb 16 '21

Did you check the following section in the docs?

Bigger Applications - Multiple Files