---
title: "Use FastAPI for a Python API · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/web-frameworks/fastapi
updated: 2026-10-21
licence: "All rights reserved"
---

# Use FastAPI for a Python API

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

- Level: Optional
- Chapter: [Web frameworks](https://agentwranglers.se/playbook/stack/web-frameworks)
- Rule: Use FastAPI for a Python service that only answers JSON, and pin its minor version.
- Cost: Open source. MIT licence, free to run on your own servers.
- How: FastAPI first came out in December 2018, and version 0.156.8 shipped in October 2026. It has never reached version 1.0, so it fails the five-year stable test, and minor versions can break code. It passes the rest. It has about 114 million weekly downloads and an MIT licence. It was used by 18.5% of developers in the 2026 Stack Overflow survey, above Flask and Django. Record the exception as the first chapter asks. Choose something else when the app also needs pages, accounts and an admin, which Django brings. It checks input with Pydantic, as [Use Zod or Pydantic to check every input](https://agentwranglers.se/playbook/stack/web-frameworks/zod-pydantic) says.
- Check: requirements or pyproject pins FastAPI to one minor version, such as `fastapi>=0.156,<0.157`, and a decision record names the exception.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Python example

```python
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class Order(BaseModel):
    id: int
    total_cents: int

@app.get("/orders/{order_id}")
def get_order(order_id: int) -> Order:
    return Order(id=order_id, total_cents=4200)
```

### JavaScript example

```js
const PINNED_MINOR = /^fastapi>=0\.(\d+)(\.\d+)?,<0\.(\d+)$/;

export const isMinorPinned = requirement => {
  const match = PINNED_MINOR.exec(requirement.replace(/\s/g, ''));
  return Boolean(match) && Number(match[3]) === Number(match[1]) + 1;
};
```

## Sources

- [FastAPI](https://fastapi.tiangolo.com/)

## Related rules

- [Use Zod or Pydantic to check every input](https://agentwranglers.se/playbook/stack/web-frameworks/zod-pydantic) in Software choices

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/web-frameworks/fastapi">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use Django for a Python web app](https://agentwranglers.se/playbook/stack/web-frameworks/django)
- Next: [Use Zod or Pydantic to check every input](https://agentwranglers.se/playbook/stack/web-frameworks/zod-pydantic)
- [Web frameworks](https://agentwranglers.se/playbook/stack/web-frameworks)
