Skip to main content

pyscythe

Codebase intelligence for Python. Dead code, circular imports, duplication, complexity, and architecture boundaries in one fast binary. The Python answer to fallow.

Built in Rust on the ruff and ty crates, so name resolution is semantic rather than textual: a symbol is only "used" when a reference actually binds to it.

Status

Early. pyscythe dead-code reports functions, classes, methods, properties, variables, and whole files that nothing refers to, resolving references semantically through ty (aliased imports, attribute access, re-exports). Dotted strings such as "pkg.settings.DEBUG" count as references. Methods that override an inherited member (walked through ty, so library bases count) are kept, and any attribute name accessed anywhere keeps same-named methods as a duck-typing safety net. pyscythe cycles reports import cycles that would bite at load time. pyscythe health measures cyclomatic and cognitive complexity per function, lists hotspots, and grades the codebase 0 to 100. pyscythe dupes finds copied code, including renamed copies, and reports the duplicated percentage. pyscythe boundaries enforces layering rules from pyproject.toml. pyscythe fix --dry-run shows the diff that would delete the dead code, and pyscythe fix applies it. pyscythe deps compares what pyproject.toml (PEP 621 or Poetry tables, or setup.py, setup.cfg, or pip requirements*.txt files) declares with what the code imports, per nested project in a monorepo, using the installed environment's metadata when there is one; an import that only arrives through a declared dependency (starlette via fastapi) is reported at low confidence. pytest's python_files, python_classes, and python_functions are honoured from pytest.ini, pyproject.toml, tox.ini, or setup.cfg. Built-in plugins keep symbols that frameworks reach by convention: pyproject entry points, pytest, FastAPI, Flask, Click/Typer, Celery, Airflow, Django, Graphene/GraphQL, Alembic, SQLAlchemy/SQLModel, Pydantic, Home Assistant. A project whose package is named after the distribution (django, langchain_classic) is a library, and its unimported modules are reported at low confidence since they are its users' entry points. See TODO.md for the roadmap.

Install

The binary ships as a wheel on PyPI, so any Python tool runner works, and no Python is needed at runtime:

uvx pyscythe dead-code .            # run without installing
uv tool install pyscythe            # or: pipx install pyscythe
cargo install --locked --git https://github.com/jacobsieradzki/pyscythe pyscythe   # from source

Wheels are built for Linux (x86_64, aarch64), macOS (Intel, Apple silicon), and Windows (x86_64). crates.io is not an option while the ruff and ty crates are git dependencies.

Usage

pyscythe dead-code path/to/project
pyscythe dead-code path/to/project --format json
pyscythe dead-code path/to/project --no-plugins   # report every unreferenced symbol
pyscythe dead-code path/to/project --show-kept    # list what plugins suppressed, and why
pyscythe dead-code path/to/project --exclude scripts --exclude "**/legacy_*.py"
pyscythe cycles path/to/project

Confidence: high for private module-level names, medium for public ones and private methods, low for public methods, where overriding or reflection could hide a use.

Configuration lives in pyproject.toml:

[tool.pyscythe]
exclude = ["scripts", "**/legacy_*.py"]   # left out of reports; their references still count
ignore-names = ["deprecated_*"]           # symbols never reported
entry-points = ["pkg.worker:run"]         # extra roots beyond [project.scripts]
include-notebooks = false

public-modules = ["mylib"]         # a library: public names in these modules are API, not dead

[tool.pyscythe.deps]
ignore = ["some-pytest-plugin"]   # declared on purpose, never imported

[tool.pyscythe.health]
max-cyclomatic = 10
max-cognitive = 15
max-lines = 50
max-parameters = 6

[tool.pyscythe.boundaries]
layers = ["app.api", ["app.services", "app.workers"], "app.domain"]  # top to bottom
# or: preset = "hexagonal" with root = "app"

[[tool.pyscythe.boundaries.rules]]
from = "app.domain"
deny = ["app.infra"]

Exit codes: 0 clean, 1 findings, 2 error.

In CI

As a GitHub Action, which installs the PyPI wheel with uv (the action itself lives in this repository, so the runner needs access to it while the repository is private):

- uses: jacobsieradzki/pyscythe@main
  with:
    command: dead-code
    version: 0.1.0                      # omit for the latest release
    since: origin/${{ github.base_ref }}
    args: --min-confidence medium
pyscythe dead-code --format github          # GitHub Actions annotations
pyscythe dead-code --format sarif > out.sarif
pyscythe dead-code --format pr-comment      # a table with a marker a bot can find and update
pyscythe dead-code --min-confidence medium  # skip low-confidence method findings
pyscythe dead-code --since origin/main      # only files this branch changed

Adopting on an existing codebase: record what is there today, then fail only on new findings.

pyscythe dead-code --write-baseline .pyscythe-baseline.json
pyscythe dead-code --baseline .pyscythe-baseline.json

Silence a single finding where it happens:

def kept_for_a_reason() -> None:  # pyscythe: ignore
    ...

# pyscythe: ignore[unused-method]
def another() -> None:
    ...

# pyscythe: ignore-file anywhere in a file silences the whole file. A comment that silences nothing is itself reported, so suppressions do not rot.

Developing

Rust is managed by mise, which also installs cargo-shear and typos. Every warning is an error; clippy runs with pedantic and nursery on, rustdoc denies broken links, cargo shear fails on unused dependencies, and typos checks spelling. mise run check runs the whole gate, the same one CI runs.

mise install
mise run check

For Rust, the tools that map onto oxlint, oxfmt, and fallow are clippy, rustfmt, and rustc's own dead_code and unreachable_pub lints plus cargo shear; all are wired in here.

The corpus

corpus/corpus.toml pins 35 public projects (Django, Home Assistant, pandas, pydantic, ansible, saleor, and others chosen for the shapes they add) at a commit each, with the environment for each pinned in corpus/locks. mise run corpus clones them into corpus/cache, builds their environments with uv, runs every analysis, and compares the reports with corpus/snapshots: one sorted line per finding, paths relative to the project. The corpus workflow does the same on every push and pull request, so a change in output over real code is always a visible diff in the pull request.

mise run corpus                              # check every project
mise run corpus -- --project django          # one project
mise run corpus -- --shard 2/6               # one slice, as the CI matrix runs them
mise run corpus:update                       # accept a deliberate change
cargo run -p pyscythe_corpus -- lock --project django   # re-resolve an environment

When a rule changes, the snapshot diff is the review: read it, make sure every line that moved is one you meant to move, then update. To add a project, add its entry to the manifest, run lock for it, then update.

Releasing

Bump version in the workspace Cargo.toml, commit, then tag and push:

git tag v0.2.0 && git push origin v0.2.0

The release workflow builds the wheels and sdist with maturin, publishes them to PyPI through trusted publishing (the pypi environment, no token stored anywhere), and attaches the same files to a GitHub Release. uvx maturin build --release builds a wheel locally into target/wheels.

Layout

  • crates/pyscythe_core — domain model and analyses. No parser, no filesystem. Analyses are written against the CodebaseIndex port and tested with an in-memory fake.
  • crates/pyscythe_ty — the adapter that implements CodebaseIndex on the ty project database, including the parallel reference index.
  • crates/pyscythe_pyproject — reads pyproject.toml into the manifest and config.
  • crates/pyscythe_metrics — per-function complexity from the ruff AST alone, unit-tested on snippets.
  • crates/pyscythe_cli — the pyscythe binary, output formats, and acceptance tests that run the real binary over fixture projects.

Metadata

Release files for pyscythe 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyscythe 0.2.0
File Size Uploaded Provenance Actions
pyscythe-0.2.0.tar.gz 170.4 kB With provenance Details for pyscythe-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyscythe 0.2.0
File Actions
pyscythe-0.2.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for pyscythe-0.2.0-py3-none-win_amd64.whl
pyscythe-0.2.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for pyscythe-0.2.0-py3-none-manylinux_2_28_x86_64.whl
pyscythe-0.2.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for pyscythe-0.2.0-py3-none-manylinux_2_28_aarch64.whl
pyscythe-0.2.0-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for pyscythe-0.2.0-py3-none-macosx_11_0_arm64.whl
pyscythe-0.2.0-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details for pyscythe-0.2.0-py3-none-macosx_10_12_x86_64.whl

Total release size: 55.6 MB

Release files / pyscythe-0.2.0.tar.gz

Download URL pyscythe-0.2.0.tar.gz
Size 170.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cb647d4b5695dbaf448ff014ccbfd07229272cbf7e5cc1e1935b8b67c83ae22e
BLAKE2b-256 checksum
How to use checksums
9b174d2241dceb139156f18a25d04580dd12c9c4326c339630863e412fb44831
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pyscythe-0.2.0-py3-none-win_amd64.whl

Download URL pyscythe-0.2.0-py3-none-win_amd64.whl
Size 11.4 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
ee7466c2ee7a5d1c76151cbb3870122239f4c69467b3a2c23407155dfe139fcf
BLAKE2b-256 checksum
How to use checksums
6e6ac19795d53baf67083413d69e3419bb704d38fb2e99976018ee7d9d45bda2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pyscythe-0.2.0-py3-none-manylinux_2_28_x86_64.whl

Download URL pyscythe-0.2.0-py3-none-manylinux_2_28_x86_64.whl
Size 11.5 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
7322bc037b7379af07e5d33c8b3a8b15516c6649b56c27c87a13b46b5258fcb6
BLAKE2b-256 checksum
How to use checksums
7805897f80db69960d74e2a87c28dffdec21f5ea4d1698381f87d414b6a47fb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pyscythe-0.2.0-py3-none-manylinux_2_28_aarch64.whl

Download URL pyscythe-0.2.0-py3-none-manylinux_2_28_aarch64.whl
Size 10.8 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
41377e94c9dbcca2b1ab0fa72836db37e88ee4a8a9fa08f64488b6712c0f3245
BLAKE2b-256 checksum
How to use checksums
8cc98264822a6cef211ded02640da0425c5dc64439a2326c7c5e16084ca1d63c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pyscythe-0.2.0-py3-none-macosx_11_0_arm64.whl

Download URL pyscythe-0.2.0-py3-none-macosx_11_0_arm64.whl
Size 10.7 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9febdf181e3ca800ba015854bc160ec58c3e9da97dad2bbdad2e7d2339897c1f
BLAKE2b-256 checksum
How to use checksums
e1e159089eec3762bdd28112a34f082aeb59a519dfbdf7115860c15a2fcef7ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Release files / pyscythe-0.2.0-py3-none-macosx_10_12_x86_64.whl

Download URL pyscythe-0.2.0-py3-none-macosx_10_12_x86_64.whl
Size 11.1 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bd3cf17f8d68dbd3f70da719f40d4995716422a20ae6b3be87de50f98c6a97a4
BLAKE2b-256 checksum
How to use checksums
75ae065a0936f001ff67fc59a09e20327d13eaf1894a30936f3307194a8204d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

Security for pyscythe 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for pyscythe-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page