---
source: https://iinventedlight.com/library/notes/fastapi-async-await.md
title: "async def vs def in FastAPI"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); prose restates or closely paraphrases cited source lines"
license_family: fastapi-mit
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Concurrency and async / await - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE); FastAPI docs, First Steps - FastAPI, MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: FastAPI"
tags: ['fastapi', 'async', 'concurrency']
sources:
  - id: S1
    title: "Concurrency and async / await - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/async/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
  - id: S2
    title: "First Steps - FastAPI"
    publisher: FastAPI docs
    url: https://fastapi.tiangolo.com/tutorial/first-steps/
    accessed: 2026-11-04
    license: "MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE)"
---
# async def vs def in FastAPI

**Answer:** You can mix def and async def in your path operation functions as much as you need and define each one using the best option for you. In any of the cases, FastAPI will still work asynchronously and be extremely fast. (S1)

## The rules

- You can only use await inside of functions created with async def. (S1)
- If your application doesn't have to communicate with anything else and wait for it to respond, use async def, even if you don't need to use await inside. (S1)
- Modern versions of Python have support for "asynchronous code" using something called "coroutines", with async and await syntax. (S1)
- With async def, Python knows that, inside that function, it has to be aware of await expressions. (S1)

## Related

- FastAPI generates a "schema" with all your API using the OpenAPI standard for defining APIs. (S2)
- This schema definition includes your API paths, the possible parameters they take, etc. (S2)

## Claims
- id: C1
  claim: await only works inside async def.
  source: S1
  evidence: "You can only use await inside of functions created with async def."
- id: C2
  claim: def and async def can be mixed.
  source: S1
  evidence: "declare your path operation functions with async def like"
- id: C3
  claim: Python uses coroutines for async code.
  source: S1
  evidence: "with async and await syntax."
- id: C4
  claim: FastAPI generates an OpenAPI schema.
  source: S2
  evidence: "FastAPI automatically generates a JSON (schema) with the descriptions of all your API."

## Sources
- [S1] Concurrency and async / await - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/async/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.
- [S2] First Steps - FastAPI. FastAPI docs. https://fastapi.tiangolo.com/tutorial/first-steps/ . License: MIT (fastapi/fastapi LICENSE; Copyright (c) 2018 Sebastián Ramírez; https://github.com/fastapi/fastapi/blob/master/LICENSE). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
