Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Join theFastAPI Cloud waiting list 🚀
Follow@fastapi onX (Twitter) to stay updated
FollowFastAPI onLinkedIn to stay updated
Subscribe to theFastAPI and friends newsletter 🎉
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor
sponsor

Features

FastAPI features

FastAPI gives you the following:

Based on open standards

  • OpenAPI for API creation, including declarations ofpathoperations, parameters, request bodies, security, etc.
  • Automatic data model documentation withJSON Schema (as OpenAPI itself is based on JSON Schema).
  • Designed around these standards, after a meticulous study. Instead of an afterthought layer on top.
  • This also allows using automaticclient code generation in many languages.

Automatic docs

Interactive API documentation and exploration web user interfaces. As the framework is based on OpenAPI, there are multiple options, 2 included by default.

  • Swagger UI, with interactive exploration, call and test your API directly from the browser.

Swagger UI interaction

  • Alternative API documentation withReDoc.

ReDoc

Just Modern Python

It's all based on standardPython type declarations (thanks to Pydantic). No new syntax to learn. Just standard modern Python.

If you need a 2 minute refresher of how to use Python types (even if you don't use FastAPI), check the short tutorial:Python Types.

You write standard Python with types:

fromdatetimeimportdatefrompydanticimportBaseModel# Declare a variable as a str# and get editor support inside the functiondefmain(user_id:str):returnuser_id# A Pydantic modelclassUser(BaseModel):id:intname:strjoined:date

That can then be used like:

my_user:User=User(id=3,name="John Doe",joined="2018-07-19")second_user_data={"id":4,"name":"Mary","joined":"2018-11-30",}my_second_user:User=User(**second_user_data)

Info

**second_user_data means:

Pass the keys and values of thesecond_user_data dict directly as key-value arguments, equivalent to:User(id=4, name="Mary", joined="2018-11-30")

Editor support

All the framework was designed to be easy and intuitive to use, all the decisions were tested on multiple editors even before starting development, to ensure the best development experience.

In the Python developer surveys, it's clearthat one of the most used features is "autocompletion".

The wholeFastAPI framework is based to satisfy that. Autocompletion works everywhere.

You will rarely need to come back to the docs.

Here's how your editor might help you:

editor support

editor support

You will get completion in code you might even consider impossible before. As for example, theprice key inside a JSON body (that could have been nested) that comes from a request.

No more typing the wrong key names, coming back and forth between docs, or scrolling up and down to find if you finally usedusername oruser_name.

Short

It has sensibledefaults for everything, with optional configurations everywhere. All the parameters can be fine-tuned to do what you need and to define the API you need.

But by default, it all"just works".

Validation

  • Validation for most (or all?) Pythondata types, including:

    • JSON objects (dict).
    • JSON array (list) defining item types.
    • String (str) fields, defining min and max lengths.
    • Numbers (int,float) with min and max values, etc.
  • Validation for more exotic types, like:

    • URL.
    • Email.
    • UUID.
    • ...and others.

All the validation is handled by the well-established and robustPydantic.

Security and authentication

Security and authentication integrated. Without any compromise with databases or data models.

All the security schemes defined in OpenAPI, including:

  • HTTP Basic.
  • OAuth2 (also withJWT tokens). Check the tutorial onOAuth2 with JWT.
  • API keys in:
    • Headers.
    • Query parameters.
    • Cookies, etc.

Plus all the security features from Starlette (includingsession cookies).

All built as reusable tools and components that are easy to integrate with your systems, data stores, relational and NoSQL databases, etc.

Dependency Injection

FastAPI includes an extremely easy to use, but extremely powerfulDependency Injection system.

  • Even dependencies can have dependencies, creating a hierarchy or"graph" of dependencies.
  • Allautomatically handled by the framework.
  • All the dependencies can require data from requests andaugment the path operation constraints and automatic documentation.
  • Automatic validation even forpath operation parameters defined in dependencies.
  • Support for complex user authentication systems,database connections, etc.
  • No compromise with databases, frontends, etc. But easy integration with all of them.

Unlimited "plug-ins"

Or in other way, no need for them, import and use the code you need.

Any integration is designed to be so simple to use (with dependencies) that you can create a "plug-in" for your application in 2 lines of code using the same structure and syntax used for yourpath operations.

Tested

  • 100%test coverage.
  • 100%type annotated code base.
  • Used in production applications.

Starlette features

FastAPI is fully compatible with (and based on)Starlette. So, any additional Starlette code you have, will also work.

FastAPI is actually a sub-class ofStarlette. So, if you already know or use Starlette, most of the functionality will work the same way.

WithFastAPI you get all ofStarlette's features (as FastAPI is just Starlette on steroids):

Pydantic features

FastAPI is fully compatible with (and based on)Pydantic. So, any additional Pydantic code you have, will also work.

Including external libraries also based on Pydantic, asORMs,ODMs for databases.

This also means that in many cases you can pass the same object you get from a requestdirectly to the database, as everything is validated automatically.

The same applies the other way around, in many cases you can just pass the object you get from the databasedirectly to the client.

WithFastAPI you get all ofPydantic's features (as FastAPI is based on Pydantic for all the data handling):


[8]ページ先頭

©2009-2026 Movatter.jp