简体   繁体   中英

Migrating from Flask to FastAPI

I'm developing two applications in FastAPI, which would use same data model structures - they both operate over same database but under different users with different credentials information. Therefore in my project structure, I created three folders - one for FastAPI project application A(python backend for frontend application), one for FastAPI project application B(python backend for backoffice users application) and one for common classes including files with SQLAlchemy tables definition - folder C. In flask, everything was working like a charm - each from application A and B had separate config files with different credentials for database. I didn't have any problems with correct connection to database. Based on what project I started, correct database credentials were used. I used flask_sqlalchemy extension and it took care of everything. Now, I'm having Settings file for each application A and B, which contain correct credentials and database connection string. Problem is, that I want to have code in folder C independent on folders A and B. That means that I would like to somehow write without dependency on project A or project B SQLAlchemy files with description of common database structures. I have no idea currently whether is this feasible or how to do it. I think that this kind of code and application separation is good and maybe even necessary idea in terms of security - I'm using users with different sets of permissions for each application. Just have no idea how to somehow correctly provide dependency of code in folder C to correct database credentials.

I found additional package designed specifically for use of SQL alchemy with FastAPI which solves my problem: https://pypi.org/project/FastAPI-SQLAlchemy/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM