📜  fastapi - Python (1)

📅  最后修改于: 2023-12-03 15:15:02.623000             🧑  作者: Mango

FastAPI - Python

Introduction

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints. It was originally created by Sebastián Ramírez and is now developed and maintained by a growing community of contributors.

FastAPI allows you to easily build fast, highly efficient and scalable APIs with minimal boilerplate code. It is built on top of established web frameworks such as Starlette and Pydantic, and it leverages the outstanding performance of Python's asynchronous I/O framework, AsyncIO.

Features
  • Fast: Very high performance, thanks to its unique combination of techniques, including async/await, Cython, and Starlette for the web parts.
  • Fast to code: Increase the speed to develop features by about 200%. *
  • Fewer bugs: Reduce about 40% of human (developer) induced errors.
  • Intuitive: Great editor support. Completion everywhere. Less time debugging.
  • Easy: Designed to be easy to use and learn. Less time reading docs.
  • Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
  • Robust: Get production-ready code. With automatic interactive documentation.
Getting Started

To get started with FastAPI, you'll need to install it first using pip:

!pip install fastapi

Create a new file called main.py:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello World"}

Now, run the API server using:

uvicorn main:app --reload

FastAPI automatically generates an interactive documentation (similar to Swagger UI) that you can access by visiting http://localhost:8000/docs. You can also try out your API using the 'Try it out' feature present in the documentation.

Conclusion

FastAPI is a powerful and performant web framework for building APIs with Python. If you're looking for a framework that is easy to use, scalable and efficient, FastAPI is a great choice. It's also well-documented and has a large community of developers working on it, which means you can get help when you need it. Give it a try and see how it can improve your API development workflow!

Data based on a survey of over 380 developers conducted by the FastAPI team in April 2020. Source: FastAPI - Python*