📜  fastapi (1)

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

FastAPI - A Modern Web Framework for Fast and Powerful Development

FastAPI is a modern, fast (high-performance) web framework for building APIs with Python 3.6+ based on standard Python type hints. It was created to be easy to use, fast to develop with, and provide high-performance.

Features
  • Fast: Very high performance, thanks to Pydantic and async support.
  • Fast to code: Type hints and automatic docs let you focus on business logic.
  • Fewer bugs: Less code means fewer bugs.
  • Clean code: Type hints and classes enforce a clean architecture on your codebase.
  • Easy: Designed to be easy to use and learn. Less time reading docs.
  • Short: Minimize code duplication. Multiple features from each parameter declaration.
  • Robust: Get production-ready code. With automatic interactive documentation.
Getting Started

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

pip install fastapi

You'll also need to install a web server to run FastAPI. For development purposes, we recommend using uvicorn:

pip install uvicorn

Once you've installed FastAPI and uvicorn, you're ready to start building your API. Here's a simple example:

from fastapi import FastAPI

app = FastAPI()

@app.get('/')
async def root():
    return {'message': 'Hello, FastAPI!'}
Documentation

FastAPI comes with automatic interactive documentation. To access the documentation, visit http://localhost:8000/docs in your web browser. This documentation provides a user interface for testing your API, as well as detailed documentation for each endpoint.

Conclusion

FastAPI is a powerful and easy-to-use web framework for building APIs with Python. With automatic documentation, robust architecture enforcement, and high performance, it's a great choice for anyone looking to build APIs quickly and reliably.