FastAPIApp/
├── app.py
├── templates/
│ └── index.html
├── static/
│ └── flask-logo.png
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to FastAPI</title>
</head>
<body>
<h1>Welcome to FastAPI</h1>
<img src="{{ url_for('static', path='/flask-logo.png') }}" alt="Flask Logo" />
<p>Welcome to FastAPI's documentation. Get started with <a href="#">installation</a>
and then get an overview with the <a href="#">quickstart</a>. There is also a
more detailed <a href="#">tutorial</a> that shows how to create a small but
complete application with FastAPI. Common patterns are described in the
<a href="#">patterns</a> section. The rest of the docs describe each
component of FastAPI in detail, with a full reference in the <a href="#">API</a>
section.</p>
</body>
</html>
This allows for async functions to be passed to the Flask class
instance, for example as a view function,
@app.route("/")
async def index():
return "Async hello"
this comes with a cost though of poorer performance than using the
sync equivalent.
asgiref is the standard way to run async code within a sync context,
and is used in Django making it a safe and sane choice for this.
new readme
readme as setup.py long_description
links in changes
git in authors
add travis osx env
break out docs build in travis
remove python_requires for now