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.3.tar.gz (155.1 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.3-cp310-abi3-win_amd64.whl (132.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

prune_source-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (225.7 kB view details)

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

prune_source-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (217.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

prune_source-0.1.3-cp310-abi3-macosx_11_0_arm64.whl (204.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

prune_source-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl (212.5 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: prune_source-0.1.3.tar.gz
  • Upload date:
  • Size: 155.1 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.3.tar.gz
Algorithm Hash digest
SHA256 ed0a8adf9e6b5a0c9fcf10a166147e436389f63132fe6a86cd7906cb06c6a90b
MD5 00e957fcd5697868dd272cbbd15a8e2a
BLAKE2b-256 06fa3ba6ee34529c97a085adec4eb28f9b8587a8120dc8e4020179cf4fc428ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3.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.3-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: prune_source-0.1.3-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 132.4 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.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 61df0ddc8b441c2e9ac6449635fd100168b5e6dc9f566960570283794ebb004c
MD5 7de10e72c8fa07b6d4a27973c07c3f17
BLAKE2b-256 8726da9c3ed42ea4e3e7a1741e4692926391458397496b6bf9dd0f887284ac7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3-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.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: prune_source-0.1.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 225.7 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.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86724c5e6bc94b6ce25a6d69afdd4b3cc3f4dd3009fb5f6b683019fafe8d4a2c
MD5 fa67abfdc89f5f582f7a727f11384ce9
BLAKE2b-256 dcbb9a5cbdf9788aef96ff7d50c18551be1714626f75cd600b80d8327d6b6887

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3-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.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: prune_source-0.1.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 217.4 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.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 24b419208af803c04b8c7d108374ecfaf113cdcb3bb60f911f07128024bb1fc3
MD5 ddf3edeb0b1325a43bfbc6aad787bc6e
BLAKE2b-256 f58da59416c93a191cf6642d20068c8158ac63883cbeb0b211128fae60181664

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3-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.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: prune_source-0.1.3-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 204.3 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.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 db0540dcd8f017415ba8b872c94363099813b823c61dc8c4b055f8b99806607f
MD5 586f94e023b87f19456fd3de230848ae
BLAKE2b-256 d63b834def1d15401d8eaf2e813f5a766253b348354cbad5cd86d4068640ac63

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3-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.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: prune_source-0.1.3-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 212.5 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.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 560e96148def564df7d9cb99492896c0c154424cfffe2649f96707c307233904
MD5 bb06a468867483a04d981d3c2528e773
BLAKE2b-256 18653da4cb2da0c2d3f02d1a766c6ed001e537f55e7f5b54278a42c3f43e70a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for prune_source-0.1.3-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

0.1.4

6 files

This release

0.1.3 This release

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