Python 3.15 adds these features, as What's New in 3.15 lists.
lazy import json and lazy from pathlib import Path defer the import until first use (PEP 810). They work only at module scope.
- UTF-8 is the default encoding when no
encoding argument is given (PEP 686). PYTHONUTF8=0 or -X utf8=0 restores the locale encoding.
frozendict is a built-in immutable mapping (PEP 814), and sentinel creates unique sentinel values (PEP 661).
- Comprehensions accept unpacking, as in
[*xs for xs in lists] (PEP 798).
- The
profiling package adds the profiling.sampling profiler and profiling.tracing, which replaces cProfile (PEP 799).
- Typing adds
TypedDict with extra_items and closed (PEP 728), TypeForm (PEP 747), and disjoint bases (PEP 800).
Python 3.14 adds these features, as What's New in 3.14 lists.
- Annotations are evaluated lazily (PEP 649 and 749), so forward references need no quotes and no
from __future__ import annotations. Read them with annotationlib.get_annotations().
- Template strings such as
t"Hello {name}" produce a string.templatelib.Template instead of a str (PEP 750). They let a library escape values safely, as for SQL or HTML.
- The free-threaded build without the GIL is officially supported (PEP 779).
compression.zstd adds Zstandard compression (PEP 784), and concurrent.interpreters with InterpreterPoolExecutor adds subinterpreters (PEP 734).
except A, B: works without parentheses when there is no as clause (PEP 758).
- A
return, break, or continue that leaves a finally block emits a SyntaxWarning (PEP 765).
- On Unix other than macOS, the default
multiprocessing start method is forkserver.
A project has pyproject.toml or uv.lock, and these commands manage it.
uv init creates a new project. By default it uses a src layout and the uv_build build backend.
uv add requests adds a dependency, and uv add --dev pytest adds it to the dev group.
uv remove requests removes a dependency.
uv sync installs the environment from the lockfile. In CI, uv sync --locked fails if the lockfile is out of date.
uv lock --upgrade-package requests upgrades one locked package.
uv run <command> runs a command in the project environment, and uv run python -c "..." runs Python there.
uv run -p 3.14 <command> runs a command with a specific Python version.
A standalone script uses inline metadata (PEP 723), and these commands manage it.
uv run script.py runs the script.
uv run --with requests script.py runs it with an extra package.
uv add --script script.py requests writes the dependency into the script's metadata.
uvx <tool> runs a command-line tool from PyPI without installing it, and uvx <tool>@<version> runs a specific version. It installs packages by name, so run only well-known tools. Use uv tool install only when the user asks for it.
The pip interface serves projects that keep requirements.txt files and have no uv.lock. It uses uv venv, uv pip install -r requirements.txt, uv pip compile requirements.in -o requirements.txt, and uv pip sync requirements.txt. Add --universal to uv pip compile for a platform-independent result. Do not add new requirements.txt files to a uv project.
In a uv project, these replacements apply.
| Instead of |
Use |
pip install requests |
uv add requests |
python script.py |
uv run script.py |
python -c "..." |
uv run python -c "..." |
python3.12 -c "..." |
uvx python@3.12 -c "..." |
python -m venv .venv and source .venv/bin/activate |
uv run <command> |
These commands replace the older tools when the user asks to migrate.
| Old command |
uv command |
pyenv install 3.14 |
uv python install 3.14 |
pyenv versions |
uv python list --only-installed |
pyenv local 3.14 |
uv python pin 3.14 |
pyenv global 3.14 |
uv python install 3.14 --default |
pipx run ruff |
uvx ruff |
pipx install ruff |
uv tool install ruff |
pipx upgrade ruff |
uv tool upgrade ruff |
pipx list |
uv tool list |
pip install -r req.txt |
uv pip install -r req.txt |
pip freeze |
uv pip freeze |
pip-compile req.in |
uv pip compile req.in |
pip-sync req.txt |
uv pip sync req.txt |
virtualenv .venv |
uv venv |
The uv documentation index links to a page for each workflow.
Keep ruff's changes inside the task. If ruff format --diff changes a whole file, the project does not format with ruff. Leave that file unformatted. ruff check --diff shows the fixes for the code you change. Apply fixes only to the files you modify, unless the user asks for more.
These commands cover daily use.
ruff check . lints the directory, and ruff check path/to/file.py lints one file.
ruff check --fix . applies the safe fixes.
ruff check --select E,F . checks only some rules, and --ignore E501 skips one.
ruff rule E501 explains a rule.
ruff format . formats the code, ruff format --check . only checks it, and ruff format --diff . shows the diff.
Run ruff check --fix before ruff format, because a lint fix can change the structure that the formatter then cleans up. Some fixes are unsafe because they can change behavior. For example, removing an unused import breaks code that relies on its side effects. Ruff 0.17 shows unsafe fixes by default, but applies them only with --unsafe-fixes. Preview them with ruff check --fix --unsafe-fixes --diff ., and read ruff rule <CODE> before you apply them.
This configuration in pyproject.toml enables rule sets beyond the defaults and sets the first-party package for import sorting.
[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B"]
ignore = ["E501"]
[tool.ruff.lint.isort]
known-first-party = ["myproject"]
Without a configured Python version, ruff 0.17 assumes Python 3.11. Set requires-python in pyproject.toml or target-version in the ruff table, so that UP rules match the project. Ruff maps the older tools directly. black . becomes ruff format ., flake8 . becomes ruff check ., and isort . becomes ruff check --select I --fix .. The ruff documentation lists every rule and setting.
ty runs as uv run ty check when it is a project dependency, and as uvx ty check otherwise. ty check src/ or ty check path/to/file.py checks a part of the project. These options control the run.
--python-version 3.14 and --python-platform linux set the target environment.
--error <rule>, --warn <rule>, and --ignore <rule> change the level of one rule.
--output-format concise prints one line per diagnostic.
ty reads its configuration from [tool.ty] tables in pyproject.toml or from ty.toml. This example sets the target version, the checked paths, and two rule levels.
[tool.ty.environment]
python-version = "3.14"
[tool.ty.src]
include = ["src", "tests"]
exclude = ["**/migrations/**"]
[tool.ty.rules]
possibly-unresolved-reference = "warn"
division-by-zero = "error"
ty fails on warnings by default, and error-on-warning = false under [tool.ty.terminal] turns that off. The rule unresolved-import is now named import-not-found, and the old name still works as an alias. Fix type errors instead of suppressing them, as the verification block of the coding instructions requires. If the user asks for a suppression, use a rule-specific comment such as # ty: ignore[import-not-found], not a blanket # type: ignore. The ty documentation lists the rules.
pytest 9 changed these behaviors, as the changelog shows.
- Configuration can use native TOML in a
[tool.pytest] table, or in a [pytest] table in pytest.toml. The older [tool.pytest.ini_options] table still works, but a project cannot use both.
strict = true turns on strict_config, strict_markers, strict_parametrization_ids, and strict_xfail. A new project sets it.
- The
subtests fixture is built in and still marked experimental.
- Code that raised
PytestRemovedIn9Warning now fails.
- pytest 9.2 makes the
indirect, ids, and scope arguments of parametrize keyword-only.
This configuration fits a new project.
[tool.pytest]
strict = true
testpaths = ["tests"]
addopts = ["-ra"]
1---2name: python3description: Gives current Python practice for uv, ruff, ty, and pytest, with Django and FastAPI references. Use it whenever you write, review, upgrade, or set up Python code, including dependencies, virtual environments, scripts, linting, formatting, type checking, and pytest tests. Use it for every Django or FastAPI change, because it routes to framework references.4license: MIT for SKILL.md (uv, ruff, and ty guidance from astral-sh/claude-code-plugins). Apache-2.0 for references/django-performance.md, adapted from getsentry/skills django-perf-review with headings and checklists converted to XML sections and prose, code comments moved to prose, the report template rewritten as prose, Sentry tooling references removed, one model example fixed, and a Django 6.1 fetch mode note added. See the distribution LICENSE.5metadata:6 source: https://skillmd.com/skills/dayfinggg/python7---89<project_first>10The project's own Python version and tools come first, as `code_rules` requires. Read `requires-python` in `pyproject.toml`, `.python-version`, and the lockfile before you write code. The lockfile shows the package manager, such as `uv.lock`, `poetry.lock`, `pdm.lock`, `Pipfile.lock`, or plain `requirements*.txt`. The `pyproject.toml` tool tables and config files show the linter, formatter, type checker, and test runner. Use only syntax that the lowest allowed Python version supports. The modern defaults in this skill apply to new projects, or when the user asks for them.11</project_first>1213<python_versions>14Python 3.15 is the current release. It came out on October 9, 2026, and 3.14 came out on October 7, 2025. A new project targets 3.14 or 3.15, as long as its main dependencies support that version.1516Python 3.15 adds these features, as [What's New in 3.15](https://docs.python.org/3/whatsnew/3.15.html) lists.17- `lazy import json` and `lazy from pathlib import Path` defer the import until first use (PEP 810). They work only at module scope.18- UTF-8 is the default encoding when no `encoding` argument is given (PEP 686). `PYTHONUTF8=0` or `-X utf8=0` restores the locale encoding.19- `frozendict` is a built-in immutable mapping (PEP 814), and `sentinel` creates unique sentinel values (PEP 661).20- Comprehensions accept unpacking, as in `[*xs for xs in lists]` (PEP 798).21- The `profiling` package adds the `profiling.sampling` profiler and `profiling.tracing`, which replaces `cProfile` (PEP 799).22- Typing adds `TypedDict` with `extra_items` and `closed` (PEP 728), `TypeForm` (PEP 747), and disjoint bases (PEP 800).2324Python 3.14 adds these features, as [What's New in 3.14](https://docs.python.org/3/whatsnew/3.14.html) lists.25- Annotations are evaluated lazily (PEP 649 and 749), so forward references need no quotes and no `from __future__ import annotations`. Read them with `annotationlib.get_annotations()`.26- Template strings such as `t"Hello {name}"` produce a `string.templatelib.Template` instead of a `str` (PEP 750). They let a library escape values safely, as for SQL or HTML.27- The free-threaded build without the GIL is officially supported (PEP 779).28- `compression.zstd` adds Zstandard compression (PEP 784), and `concurrent.interpreters` with `InterpreterPoolExecutor` adds subinterpreters (PEP 734).29- `except A, B:` works without parentheses when there is no `as` clause (PEP 758).30- A `return`, `break`, or `continue` that leaves a `finally` block emits a `SyntaxWarning` (PEP 765).31- On Unix other than macOS, the default `multiprocessing` start method is `forkserver`.32</python_versions>3334<modern_code>35Modern Python code uses these defaults where the project has no other convention.36- Use built-in generics and union syntax, such as `list[int]`, `dict[str, Any]`, and `int | None`.37- Use type parameter syntax from Python 3.12, such as `def first[T](items: list[T]) -> T` and `type Pair = tuple[int, int]`.38- Mark overriding methods with `typing.override`, and return `typing.Self` from methods that return their own instance.39- Use `dataclasses` with `frozen=True` and `slots=True` for plain value types, and Pydantic models where data crosses a boundary.40- Use `pathlib.Path` for file paths, f-strings for formatting, and `match` for structural branching.41- Pass `encoding` explicitly when a file must be portable to Python 3.14 or older.42</modern_code>4344<uv>45uv is the package and project manager from Astral. It replaces pip, pip-tools, pipx, pyenv, virtualenv, and Poetry. The current release is 0.13. Use uv when the project has `uv.lock` or a `[tool.uv]` table. A uv header in `requirements*.txt` files also shows it. Do not use uv in a project that Poetry or PDM manages, which `poetry.lock` or `pdm.lock` shows. Use that tool instead.4647A project has `pyproject.toml` or `uv.lock`, and these commands manage it.48- `uv init` creates a new project. By default it uses a `src` layout and the `uv_build` build backend.49- `uv add requests` adds a dependency, and `uv add --dev pytest` adds it to the `dev` group.50- `uv remove requests` removes a dependency.51- `uv sync` installs the environment from the lockfile. In CI, `uv sync --locked` fails if the lockfile is out of date.52- `uv lock --upgrade-package requests` upgrades one locked package.53- `uv run <command>` runs a command in the project environment, and `uv run python -c "..."` runs Python there.54- `uv run -p 3.14 <command>` runs a command with a specific Python version.5556A standalone script uses inline metadata (PEP 723), and these commands manage it.57- `uv run script.py` runs the script.58- `uv run --with requests script.py` runs it with an extra package.59- `uv add --script script.py requests` writes the dependency into the script's metadata.6061`uvx <tool>` runs a command-line tool from PyPI without installing it, and `uvx <tool>@<version>` runs a specific version. It installs packages by name, so run only well-known tools. Use `uv tool install` only when the user asks for it.6263The pip interface serves projects that keep `requirements.txt` files and have no `uv.lock`. It uses `uv venv`, `uv pip install -r requirements.txt`, `uv pip compile requirements.in -o requirements.txt`, and `uv pip sync requirements.txt`. Add `--universal` to `uv pip compile` for a platform-independent result. Do not add new `requirements.txt` files to a uv project.6465In a uv project, these replacements apply.6667| Instead of | Use |68| --- | --- |69| `pip install requests` | `uv add requests` |70| `python script.py` | `uv run script.py` |71| `python -c "..."` | `uv run python -c "..."` |72| `python3.12 -c "..."` | `uvx python@3.12 -c "..."` |73| `python -m venv .venv` and `source .venv/bin/activate` | `uv run <command>` |7475These commands replace the older tools when the user asks to migrate.7677| Old command | uv command |78| --- | --- |79| `pyenv install 3.14` | `uv python install 3.14` |80| `pyenv versions` | `uv python list --only-installed` |81| `pyenv local 3.14` | `uv python pin 3.14` |82| `pyenv global 3.14` | `uv python install 3.14 --default` |83| `pipx run ruff` | `uvx ruff` |84| `pipx install ruff` | `uv tool install ruff` |85| `pipx upgrade ruff` | `uv tool upgrade ruff` |86| `pipx list` | `uv tool list` |87| `pip install -r req.txt` | `uv pip install -r req.txt` |88| `pip freeze` | `uv pip freeze` |89| `pip-compile req.in` | `uv pip compile req.in` |90| `pip-sync req.txt` | `uv pip sync req.txt` |91| `virtualenv .venv` | `uv venv` |9293The [uv documentation index](https://docs.astral.sh/uv/llms.txt) links to a page for each workflow.94</uv>9596<ruff>97Ruff is Astral's linter and formatter. It replaces Flake8, isort, Black, pyupgrade, and autoflake. The current release is 0.17. Use it when the project has a `[tool.ruff]` table, a `ruff.toml`, or a `.ruff.toml` file. Run `uv run ruff` when ruff is a project dependency, so that the pinned version runs. Run `uvx ruff` when it is not a dependency.9899Keep ruff's changes inside the task. If `ruff format --diff` changes a whole file, the project does not format with ruff. Leave that file unformatted. `ruff check --diff` shows the fixes for the code you change. Apply fixes only to the files you modify, unless the user asks for more.100101These commands cover daily use.102- `ruff check .` lints the directory, and `ruff check path/to/file.py` lints one file.103- `ruff check --fix .` applies the safe fixes.104- `ruff check --select E,F .` checks only some rules, and `--ignore E501` skips one.105- `ruff rule E501` explains a rule.106- `ruff format .` formats the code, `ruff format --check .` only checks it, and `ruff format --diff .` shows the diff.107108Run `ruff check --fix` before `ruff format`, because a lint fix can change the structure that the formatter then cleans up. Some fixes are unsafe because they can change behavior. For example, removing an unused import breaks code that relies on its side effects. Ruff 0.17 shows unsafe fixes by default, but applies them only with `--unsafe-fixes`. Preview them with `ruff check --fix --unsafe-fixes --diff .`, and read `ruff rule <CODE>` before you apply them.109110This configuration in `pyproject.toml` enables rule sets beyond the defaults and sets the first-party package for import sorting.111112```toml113[tool.ruff.lint]114select = ["E", "F", "I", "UP", "B"]115ignore = ["E501"]116117[tool.ruff.lint.isort]118known-first-party = ["myproject"]119```120121Without a configured Python version, ruff 0.17 assumes Python 3.11. Set `requires-python` in `pyproject.toml` or `target-version` in the ruff table, so that `UP` rules match the project. Ruff maps the older tools directly. `black .` becomes `ruff format .`, `flake8 .` becomes `ruff check .`, and `isort .` becomes `ruff check --select I --fix .`. The [ruff documentation](https://docs.astral.sh/ruff/) lists every rule and setting.122</ruff>123124<type_checking>125Use the type checker that the project already runs, such as mypy, Pyright, basedpyright, or ty. Its config sits in `pyproject.toml` or in `mypy.ini`, `pyrightconfig.json`, or `ty.toml`. Run it through the project's environment, as in `uv run mypy .`. For a new project, ty is the fast default from Astral. It is still versioned 0.0.x and renames rules at times, so pin its version.126127ty runs as `uv run ty check` when it is a project dependency, and as `uvx ty check` otherwise. `ty check src/` or `ty check path/to/file.py` checks a part of the project. These options control the run.128- `--python-version 3.14` and `--python-platform linux` set the target environment.129- `--error <rule>`, `--warn <rule>`, and `--ignore <rule>` change the level of one rule.130- `--output-format concise` prints one line per diagnostic.131132ty reads its configuration from `[tool.ty]` tables in `pyproject.toml` or from `ty.toml`. This example sets the target version, the checked paths, and two rule levels.133134```toml135[tool.ty.environment]136python-version = "3.14"137138[tool.ty.src]139include = ["src", "tests"]140exclude = ["**/migrations/**"]141142[tool.ty.rules]143possibly-unresolved-reference = "warn"144division-by-zero = "error"145```146147ty fails on warnings by default, and `error-on-warning = false` under `[tool.ty.terminal]` turns that off. The rule `unresolved-import` is now named `import-not-found`, and the old name still works as an alias. Fix type errors instead of suppressing them, as the `verification` block of the coding instructions requires. If the user asks for a suppression, use a rule-specific comment such as `# ty: ignore[import-not-found]`, not a blanket `# type: ignore`. The [ty documentation](https://docs.astral.sh/ty/) lists the rules.148</type_checking>149150<pytest>151pytest is the default test runner, and its current release is 9.2. It needs Python 3.10 or later. Run one test with `uv run pytest tests/test_users.py::test_create -q`. The `tdd` and `testing` skills cover test design.152153pytest 9 changed these behaviors, as the [changelog](https://docs.pytest.org/en/stable/changelog.html) shows.154- Configuration can use native TOML in a `[tool.pytest]` table, or in a `[pytest]` table in `pytest.toml`. The older `[tool.pytest.ini_options]` table still works, but a project cannot use both.155- `strict = true` turns on `strict_config`, `strict_markers`, `strict_parametrization_ids`, and `strict_xfail`. A new project sets it.156- The `subtests` fixture is built in and still marked experimental.157- Code that raised `PytestRemovedIn9Warning` now fails.158- pytest 9.2 makes the `indirect`, `ids`, and `scope` arguments of `parametrize` keyword-only.159160This configuration fits a new project.161162```toml163[tool.pytest]164strict = true165testpaths = ["tests"]166addopts = ["-ra"]167```168</pytest>169170<framework_references>171Read the framework reference before you change code in a framework project. The dependencies in `pyproject.toml` or the lockfile show the framework.172- A Django project starts with [references/django.md](references/django.md). It covers Django 5.2 LTS, 6.0, and 6.1 facts and access control for views, Django REST framework, and the admin.173- A Django performance review, or work on slow views and querysets, uses [references/django-performance.md](references/django-performance.md). It finds N+1 queries, unbounded querysets, and missing indexes, and it validates each finding before it reports.174- A FastAPI project reads [references/fastapi.md](references/fastapi.md). It covers the FastAPI releases up to 0.162, dependencies, lifespan, request and response models, streaming, security, and testing.175</framework_references>