Skip to content

jeanth20/flask_file_dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

flask_file_dir

flask_file_dir

To integrate a Flask endpoint into a FastAPI setup, you can follow these general steps:

Install the flask package if it's not already installed:

bash

pip install flask

Create a Flask endpoint as you normally would:

python

from flask import Flask

app_flask = Flask(name)

@app_flask.route('/my-flask-endpoint') def my_flask_endpoint(): return 'Hello from Flask!'

Create a FastAPI endpoint that proxies the Flask endpoint:

python

from fastapi import FastAPI from starlette.middleware.wsgi import WSGIMiddleware

app_fastapi = FastAPI()

mount the Flask app as a sub application

app_fastapi.mount("/my-flask-endpoint", WSGIMiddleware(app_flask))

In the example above, we mount the Flask app as a sub-application of the FastAPI app using the WSGIMiddleware from the starlette package. This allows the Flask app to run under the same server as the FastAPI app, and makes it accessible through the /my-flask-endpoint path.

Now when you run your FastAPI app, the Flask endpoint will also be available under the path /my-flask-endpoint.

flask file explorer

#@router.get("/file-directory/{token}") from fastapi import FastAPI from fastapi.responses import HTMLResponse from fastapi.middleware.wsgi import WSGIMiddleware from flask import Flask

app = FastAPI()

Create a Flask application

flask_app = Flask(name)

Define a Flask route

@flask_app.route('/paperwork') def index(): return 'Hello from Flask!'

Mount the Flask application inside the FastAPI app using WSGIMiddleware

app.mount('/flask', WSGIMiddleware(flask_app))

Define a FastAPI route

@app.get('/') def read_root(): return {'Hello': 'World'}

About

flask_file_dir

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published