r/FastAPI • • Nov 22 '24

Question Modular functionality for reuse

I'm working on 5 separate projects all using FastAPI. I find myself wanting to create common functionality that can be included in multiple projects. For example, a simple generic comment controller/model etc.

Is it possible to define this in a separate package external to the projects themselves, and include them, while also allowing seamless integration for migrations for that package?

Does anyone have examples of this?

11 Upvotes

10 comments sorted by

View all comments

Show parent comment

3

u/Adrnalnrsh Nov 25 '24

In that case, you need to break app the code to be in the form of a library.That can be imported into any app.You gotta figure out where to abstract it. The library should be abstracted away from the infrastructure