➖ Drop `pydantic-ai` dependency, use `pydantic-ai-slim[openai]` instead by YuriiMotov · Pull Request #16526 · fastapi/fastapi · GitHub
Skip to content

➖ Drop pydantic-ai dependency, use pydantic-ai-slim[openai] instead - #16526

Open
YuriiMotov wants to merge 2 commits into
masterfrom
switch-to-pydantic-ai-slim
Open

YuriiMotov wants to merge 2 commits into
masterfrom
switch-to-pydantic-ai-slim

Conversation

@YuriiMotov

@YuriiMotov YuriiMotov commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Description

We don't actually need the full pydantic-ai package.
I checked translation works well with just pydantic-ai-slim[openai].

It allows us to drop 41 sub-dependencies and avoid some useless Dependabot PRs like this.

Note: dropping the full pydantic-ai exposed an issue - FastAPI doesn't declare AnyIO as dependency, but actually uses it. Currently it's a sub-dependency of Starlette and if we install project with lowest depenencies, it will install AnyIO 3.X which is incompatible with how it's used in FastAPI. See the comment.
I only updated the min version in test dependencies - just to resolve failing CI, but we should probably add AnyIO as main dependency.

AI Disclaimer

Used Codex (Astra) to double-check

Checklist

  • This PR links to a GitHub Discussion for the proposed code change.
  • I added tests for the change.
  • The new or updated tests fail on the main branch and pass on this PR.
  • Coverage stays at 100%.
  • The documentation explains the change if needed.

@YuriiMotov YuriiMotov added internal Internal changes dependencies Pull requests that update a dependency file labels Oct 19, 2026
@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

📝 Docs preview

Last commit b9821e9 at: https://5a1625d6.fastapitiangolo.pages.dev

@YuriiMotov
YuriiMotov force-pushed the switch-to-pydantic-ai-slim branch from abe9424 to b9821e9 Compare October 19, 2026 12:40
Comment thread pyproject.toml

{ include-group = "docs-tests" },
"anyio[trio] >=3.2.1,<5.0.0",
"anyio[trio] >=4.1.0,<5.0.0",

@YuriiMotov YuriiMotov Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following code requires AnyIO >= 4.0.0.

fastapi/fastapi/routing.py

Lines 615 to 617 in f632658

See the MRE
from collections.abc import AsyncIterator

from fastapi import FastAPI
from fastapi.responses import EventSourceResponse
from fastapi.testclient import TestClient

app = FastAPI()


@app.get("/events", response_class=EventSourceResponse)
async def events() -> AsyncIterator[str]:
    yield "hello"


with TestClient(app) as client:
    response = client.get("/events")
    print(response.text)

The code example above works well with latest versions, but fails if you install AnyIO < 4.0.0

And with AnyIO < 4.1.0 we have several:

TypeError: run_sync() got an unexpected keyword argument 'cancellable'

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file internal Internal changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant