19
loading...
This website collects cookies to deliver better user experience
Fast: It offers very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). It is considered to be one of the fastest Python frameworks available.
Fast to code: It increases the speed to develop applications by about 200% to 300%.
Intuitive: It offers great editor support. The developer needs to spend less time debugging the code to verify whether the code syntax is correct or not.
Less bugs: It reduces about 40% of human (developer) induced bugs.
Easy: It is designed to be easy to use and learn. Also, the official documentation is lucid and well structured and thus takes less time to read.
Short: It supports minimize code duplication. It offers multiple features from each parameter declaration. It also has fewer bugs.
Standards-based: It is based on (and fully compatible with) the open standards for APIs, OpenAPI (previously known as Swagger) and JSON schema.
Robust: Get production-ready code with automatic interactive documentation.
>>> pip3 install virtualenv
>>> python3 -m venv dev
virtualenv dev
>>> source dev/bin/activate
>>> dev\Scripts\activate
>>> deactivate
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return { "Message": "Hello World" }
>>> pip install uvicorn[standard]
>>> uvicorn main:app --reload
Working with static files:
https://fastapi.tiangolo.com/tutorial/static-files/
Deploying FastAPI service on Amazon Web Services:
https://adem.sh/blog/tutorial-fastapi-aws-lambda-serverless
>> pip install flask
>>> pip3 install flask
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(host = ”---”, port = ____, debug = ___)
# Import Flask class
from flask import Flask
# Create Flask object
app = Flask(__name__)
>>> export FLASK_APP=app.py
>>> flask run
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/')
def hello_world():
return '<h1>Hello, World!</h1>
@app.route('/page/<int:pg_num>')
def content(pg_num):
return f'<h1>Displaying results for page {pg_num}</h1>'
if __name__ == "__main__"
app.run(host = ” --- ”, port = ____, debug = ___)
pip3 install flask[async]
@app.route("/embed/<embed_id>")
async def get_embed(embed_id):
data = await async_render_embed(embed_id)
return data