# Upgrade a Django REST Framework API to Python 3.13

Yes. An agent checks which Python your pinned packages support, moves every version pin to 3.13, installs and tests on it in its sandbox and opens a pull request.

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

## What the agent does

The agent starts with the question most upgrades skip: which Python do the pinned packages actually declare. In an API shaped like HackSoftware/Django-Styleguide-Example, `requirements/base.txt` pins `Django==5.2.7`, `djangorestframework==3.16.1`, `psycopg2==2.9.11`, `celery==5.5.3`, `django-celery-beat`, `django-celery-results`, `drf-jwt`, `django-filter`, `django-structlog[celery]`, `boto3`, `sentry-sdk` and `gunicorn`, and `requirements/local.txt` adds `pytest==8.4.2`, `pytest-django==4.11.1`, `factory-boy`, `mypy==1.18.2`, `django-stubs==5.2.7`, `djangorestframework-stubs==3.16.4`, `boto3-stubs` and `ruff==0.14.0`. For each pin the agent reads the release's metadata from PyPI, `https://pypi.org/pypi/<package>/<version>/json`, and its `Programming Language :: Python :: 3.x` classifiers. Django 5.2.7, DRF 3.16.1, celery 5.5.3 and django-stubs 5.2.7 list 3.13 as the newest version they support; psycopg2 2.9.11 and mypy 1.18.2 go one further. The highest version every pin declares is 3.13, which is the target the agent proposes, and the pull request shows the table so a reviewer sees why it did not pick 3.14.

Then it finds every place the current version is written, and there are more than the obvious two. `runtime.txt` says `python-3.12.4`; `docker/local.Dockerfile` and `docker/production.Dockerfile` both start `FROM python:3.12.4`; `.github/workflows/django.yml` has a `build` job with `actions/setup-python@v5` at `python-version: 3.12.4` and a second pip cache keyed on the path `/opt/hostedtoolcache/Python/3.12.4/x64/`, which silently stops matching when the version changes; `.pre-commit-config.yaml` sets `default_language_version` to `python3.12.1`, a different patch from everything else; `pyproject.toml` has `target-version = "py312"` under `[tool.ruff]`; and the README's Heroku section says the version lives in `.python-version`, a file the repository does not contain. The `docker-compose.yml` even carries `version: "3.12.4"` at the top, which is the compose file format field holding a Python version by mistake. The agent lists all of these as the inventory, changes each to 3.13 where it is a real pin, and reports the compose line and the missing `.python-version` as findings rather than silently fixing what it was not asked to.

Verification follows the repository's own CI. `django.yml` runs two jobs: `docker_build` does `docker compose build` and then `ruff check styleguide_example/`, `mypy --config mypy.ini styleguide_example/` and `py.test` inside the container; `build` installs `requirements/local.txt` on the runner with a `postgres` service and runs `ruff check .`, `mypy`, and `pytest`, with `pytest.ini` pointing at `config.django.test`, which sets eager Celery, a local-memory cache and the MD5 password hasher. In the sandbox the agent installs Python 3.13, creates a virtualenv, installs `requirements/local.txt`, and notes any pin that has no 3.13 wheel and has to build from source or be bumped, quoting the install error; starts Postgres in Docker as `docker-compose.yml` does; runs `ruff check .`, `mypy --config mypy.ini styleguide_example/` and `pytest -W error::DeprecationWarning` so that a `3.13` deprecation surfaces as a failure with a file and line rather than a warning nobody reads; then builds both Dockerfiles on the new base and runs the test suite inside the local image as the `docker_build` job does.

Only what the tests, the type check or the install demonstrate gets changed beyond the pins. A deprecation raised by the suite is fixed in the code that triggers it; a package that fails to install on 3.13 is bumped to the first release that works, with the error in the body; `target-version` moves to `py313` and `ruff check` is rerun, since new `UP` rules can appear even with this project's narrow `select` of `E`, `F` and `I`. The agent does not upgrade Django, DRF or celery to reach 3.14, because the request is the runtime, and says in the body that 3.14 waits on those four packages. The pull request lists each changed file, every command with its output, the classifier table and anything left blocked.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Upgrade this Django REST Framework project to the newest Python every pinned package supports, expected to be 3.13, and open a pull request. First read requirements/base.txt and requirements/local.txt and, for each pin, read its release metadata from PyPI (https://pypi.org/pypi/<package>/<version>/json) and record the highest Python version in its classifiers; the target is the highest version all of them declare. Then inventory every place the version is written: runtime.txt, every Dockerfile under docker/, .github/workflows/django.yml including any cache path that embeds the version, .pre-commit-config.yaml, pyproject.toml's ruff target-version, and any .python-version; report files the README names that do not exist, and report a version written somewhere it does not belong without changing it. Change each real pin to the target. Install the target Python, create a virtualenv, install requirements/local.txt and quote any package that fails to install; bump only such a package, to the first release that works. Start Postgres in Docker as docker-compose.yml does, then run ruff check ., mypy --config mypy.ini styleguide_example/ and pytest -W error::DeprecationWarning, and fix each failure in the code that raises it. Build both Dockerfiles on the new base and run the tests inside the local image. Do not upgrade Django, DRF or celery. Open a pull request with the classifier table, the inventory, each changed file, every command with its output and anything left blocked.",
  "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

The pull request changes the pins and little else: `runtime.txt`, both `FROM` lines under `docker/`, `python-version` and the cache path in `django.yml`, `default_language_version` in `.pre-commit-config.yaml`, `target-version` in `pyproject.toml`, and a code change wherever `pytest -W error::DeprecationWarning` pointed. The body opens with the classifier table that justifies 3.13 over 3.14, then the inventory including the compose `version` line and the missing `.python-version`, then the commands with their output.

The repository's `django.yml` runs on the pull request: `docker_build` rebuilds the image on `python:3.13` and runs ruff, mypy and pytest inside it, and `build` installs the requirements on the runner's 3.13 against a Postgres service and runs the same three. Both jobs green on the new version is the check the agent cannot fake; the sandbox run is the preview.

A reviewer confirms the target against the table, checks that no package moved without a quoted install error, reads any code change next to the deprecation that forced it, and decides what to do with the two findings the agent reported but did not change. A bump of a stubs package is read against mypy's output, since a new stubs release can add errors the suite does not.

## Run it on every quarterly runtime review

Add an automation to the Project with this prompt and a `schedule` trigger whose `cron` fires one morning in the first week of January, April, July and October, in your timezone. Each fire starts a run that reads the current pins and their classifiers again, so an API already on 3.13 gets a pull request only when every pin has come to declare 3.14; a run that finds nothing to change ends with a note instead of a pull request. `max_runs_per_hour` is irrelevant for a quarterly fire but `read_only` must stay off, since the result is a push.

Across several Django services, a script on your server lists repositories through `GET /o/{org}/github`, reads each one's `runtime.txt` or Dockerfile, and sends one `POST /o/{org}/sessions` per repository still on an older line, with a `request_id` that is a UUID v5 of the repository and the target so a retry returns the run it already started. A `webhook_url` on the key receives `run.completed` per run with `data.session_url` to read the pull request from.

## Why run it on Rush?

The slow part of a Python upgrade is not editing six version strings; it is knowing that there are six, finding out which pinned package stops you at 3.13, and running the suite with deprecations as errors on an interpreter you do not have installed. In a Rush sandbox the agent installs the target Python, reads each pin's classifiers from PyPI, runs Postgres in its own Docker, and leaves every command and its output in the transcript, including the classifier table that says why 3.14 is not yet an option.

Each service gets its own run and its own pull request, because each has its own pins and its own blocker. The checks are the repository's own two CI jobs on the new base image, and nothing merges until a person reads the table and the findings.

## Frequently asked questions

### Why 3.13 and not the newest Python?

Because the pins decide. Django 5.2.7, DRF 3.16.1, celery 5.5.3 and django-stubs 5.2.7 declare support up to 3.13 in their PyPI classifiers; going to 3.14 would mean upgrading those packages, which is a different change. The pull request shows the table so the decision is visible.

### Will it upgrade Django to get to a newer Python?

No. The prompt forbids upgrading Django, DRF or celery under a runtime change. When those packages declare the next Python, the same request, run again, proposes it.

### What about the cache path in the workflow?

`django.yml` caches `/opt/hostedtoolcache/Python/3.12.4/x64/` by path, so changing only `python-version` would leave a cache that never hits. The agent changes both and says so, because a silent cache miss is the kind of thing that makes CI slower for a year.

### What does it do with the version in docker-compose.yml?

`docker-compose.yml` begins with `version: "3.12.4"`, which is the compose file format field holding a Python version. The agent reports it as a finding and leaves it, since it is not a runtime pin and removing it is a separate decision.

### Does it run the tests against a real Postgres?

Yes, in the sandbox's own Docker, as the `build` job uses a `postgres` service and the compose file names `postgres:14.1`. `config/django/test.py` keeps Celery eager and the cache in memory, so Postgres is the only service the suite needs.

## More Django REST Framework jobs

- [Write API Tests for a Django REST Framework API](https://getrush.ai/run/write-api-tests/django-rest-framework/)
- [Add API Key Authentication to a Django REST Framework Project](https://getrush.ai/run/add-api-key-auth/django-rest-framework/)
- [Add API Versioning to a Django REST Framework Project from a Linear Issue](https://getrush.ai/run/add-api-versioning/django-rest-framework/)

## The same job on other stacks

- [Upgrade a FastAPI App to Python 3.14](https://getrush.ai/run/upgrade-python-version/fastapi/)
- [Upgrade a Flask App to Python 3.14](https://getrush.ai/run/upgrade-python-version/flask/)

## More jobs like this: Upgrade dependencies weekly

- [Upgrade Quarkus to the Latest Release](https://getrush.ai/run/upgrade-quarkus/quarkus/)

## 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/)
