# Upgrade Python Dependencies with uv in a FastAPI App

An agent runs uv lock --upgrade on a FastAPI app, keeps every bump, and shows 58 tests passing against PostgreSQL before and after, with sqlalchemy 2.1 flagged.

[Run this on Rush](https://cloud.getrush.ai/run/upgrade-uv-dependencies/fastapi/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `backend/pyproject.toml` (`requires-python = ">=3.14,<4.0"`), the root `uv.lock`, `backend/scripts/test.sh` and the test settings. The sandbox's uv 0.5.11 did not know Python 3.14, so it installed uv 0.13.6. A pip-installable Postgres lacked `uuid-ossp`, so it unpacked Debian's PostgreSQL 15 without root, created the database as UTF-8 (the first failed with `TypeError: cannot use a string pattern on a bytes-like object`), enabled `uuid-ossp` by hand and ran `alembic upgrade head`.

It runs `uv run pytest` on the untouched clone, then `uv lock --upgrade`, and again. Bumps include fastapi 0.141.1 to 0.162.0, starlette 1.3.1 to 1.10.0, sqlalchemy 2.0.51 to 2.1.6, pydantic 2.13.5 to 2.14.2. fastapi now pulls in `httpx2` and OpenTelemetry, and `python-dateutil` reached 4.0.0.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Upgrade this FastAPI app's Python dependencies with uv lock --upgrade while preserving existing compatibility constraints. Inspect backend/pyproject.toml, the root uv.lock, existing test scripts and database configuration. Start a disposable PostgreSQL database in the sandbox, install the baseline and run uv run pytest from backend with the required test environment. Update and sync the dependencies, then run the tests again against PostgreSQL. Leave out dependency groups that introduce failures and explain why. Do not touch production data, weaken tests or upgrade the frontend. Open a pull request with one line per retained package bump, exact check output and deferred upgrades.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on fastapi/full-stack-fastapi-template at f4bcfab: 1 file changed, 1311 insertions(+), 732 deletions(-), all in `uv.lock`; `pyproject.toml` and the frontend are untouched. `uv run pytest` ended `58 passed, 54 warnings` before and `58 passed, 53 warnings` after, `mypy` and `ruff` passed both times, and `ty check` exits 1 with the same `Found 3 diagnostics` on both. No group was held back. `scripts/test.sh` exited 127 because bare `coverage` is not on PATH outside `uv run`. `bumps.txt` came back as an artifact; the diff, copied as a `.diff`, did not, since capture keeps no `.diff` file. No pull request was opened.

For the reviewer: sqlalchemy 2.0 to 2.1, fastapi's new `httpx2` and OpenTelemetry dependencies, and `python-dateutil` 2 to 4 are larger than a patch bump; the tests pass, but take them now or pin them. Docker, CI and the Postgres 18 in `compose.yml` were not run.

## Run it on every Monday morning

An automation with a `schedule` trigger, `cron` `0 9 * * 1`, runs this prompt weekly against the Project's repository. The prompt asks for a disposable PostgreSQL every time, so each week's answer is a pytest line against a real database, not just a lock that resolved.

## Why run it on Rush?

A lock that resolves proves little here, because the tests open a real SQLModel session. This run set up a PostgreSQL that could run the `uuid-ossp` migrations, then showed the same 58 tests passing on both locks and named the three upgrades a reviewer should weigh.

## Frequently asked questions

### Did it change pyproject.toml?

No. Every bump fits the existing bounds, which is also why sqlalchemy 2.1 and `python-dateutil` 4 got in: `pyproject.toml` does not cap them.

### Which uv version wrote the lock?

uv 0.13.6. The lock format header did not change, but the run did not compare against the uv version the repository normally uses.

## More FastAPI jobs

- [Write k6 Load Tests for a FastAPI API](https://getrush.ai/run/write-load-tests/fastapi/)
- [Write Playwright Tests for a FastAPI and React App](https://getrush.ai/run/write-playwright-tests/fastapi/)
- [Write pytest Tests for a FastAPI App](https://getrush.ai/run/write-pytest-tests/fastapi/)

## More jobs like this: Upgrade dependencies weekly

- [Upgrade a React App From Vite 5 to the Current Vite Major](https://getrush.ai/run/upgrade-vite/vite/)
- [Upgrade a VS Code Extension to the Latest API](https://getrush.ai/run/upgrade-vscode-engine/vscode-extension/)
- [Upgrade Wagtail to the Latest Release](https://getrush.ai/run/upgrade-wagtail/wagtail/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
