Skip to main content

prune-source

prune-source is a small Rust/Ruff accelerator for static API analysis. It lexes Python source and removes function implementation suites that an API visitor does not need, allowing CPython to construct and walk a much smaller abstract syntax tree. It does not build an intermediate Ruff AST.

pip install prune-source
import ast

from prune_source import prune_source

source = "def answer() -> int:\n    return 42\n"
pruned = prune_source(source)
tree = compile(
    source if pruned is None else pruned,
    "example.py",
    "exec",
    ast.PyCF_ONLY_AST,
    optimize=1,
)

The pruner preserves function signatures, decorators, docstrings, class bodies, and class __init__ implementations. Other function suites are replaced by pass while physical line layout is retained. Removed multiline content is collapsed to empty lines rather than padded with spaces; for indented suites, the pass remains on the original final implementation line so definition end-line metadata stays stable. Nested function suites inside __init__ are pruned as well.

The input is expected to be valid for the Python interpreter that will compile it. The lexer does not perform grammar or version validation. prune_source returns None when there is nothing to prune; callers should compile their original source in that case.

Ruff's internal parser crate is vendored because its public lexer API does not expose token ranges. The vendored copy has exactly two source changes, making the range and flag accessors public; see vendor/ruff_python_parser/UPSTREAM.md.

Building from source requires Rust 1.96 or newer.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prune_source-0.1.4.tar.gz (155.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

prune_source-0.1.4-cp310-abi3-win_amd64.whl (198.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (291.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (282.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl (270.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl (278.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file prune_source-0.1.4.tar.gz.

File metadata

  • Download URL: prune_source-0.1.4.tar.gz
  • Upload date:
  • Size: 155.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4.tar.gz
Algorithm Hash digest
SHA256 48ac4438cf851b1d3b90d64fd626845517dea774ba36fcbec4f686e5f3449351
MD5 6c00a269f046717736030c235eb9fa5f
BLAKE2b-256 123f60593979053da1290f4bc77b559b517dbe60bed6c2c5f15319ac6b9d6e70

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4.tar.gz:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prune_source-0.1.4-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: prune_source-0.1.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 198.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c1f6c43d244f817bb690cd618254e986686a6fc3abef0bb0af002ae276777b45
MD5 20b12d38aadc67b663fa99f291efbce5
BLAKE2b-256 aa1bd347762fac66f0e796c26fc126e379c71dcc3544e2cf401b5d56aaf84e97

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4-cp310-abi3-win_amd64.whl:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 291.2 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c699930131071dac00649ad27a35e6515d7b93dba84670b44bfbbd3553da229
MD5 d756aaaf12844989d6b4ea02fd9313b9
BLAKE2b-256 4c4aa93058e71997787599066984e89aaf2116f249b52470318023da3ed2dfeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 282.7 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b8b932010697d51fb0e9a5f6620481af3123b7757e096c0caeedfa37fa1c6a02
MD5 3a38c85bc87bda7d65c30097206af5a6
BLAKE2b-256 73d596079410354109389b71dea9c4260806c316a19e731fc1162975dc97940c

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 270.7 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 631fb4ce4e5d99aaa4c20645baba9281dd5b1d6a49625510f8b6cdf100fe4bf5
MD5 e2f83d7d674da28e2186bdff6ffa39cc
BLAKE2b-256 d52701464f47090669c03a6a85eb6b7da1d5ec889cc8437224c9fb75bb0b5637

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 278.3 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e8e7af5de012bc272b68025cc5aaa779eea2d96b9a8387f1ffb4eeb4838394ef
MD5 10f669948d37663c9f17108752478fae
BLAKE2b-256 87853aa8695d2cbaa3e7a9bbfb6d5724acef3c9ea75d18d2b78ea1903304838e

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on pawamoy/prune-source

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.4 This release

6 files

0.1.3

6 files

0.1.0

2 files

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