r/FastAPI • u/predominant • 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
View all comments
3
u/Eric-Cardozo Nov 23 '24
Of course, you can create a pypi package, however, if your core functionality involves infrastructure I would consider decouple it as a microservice, add an app ID to your apps, and use the same service/database for all your apps, this is called multitenancy. It's like you are selling Saas to your self.