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.
The pruner uses Ruff's published parser crate to read token ranges and flags without constructing a syntax tree. Ruff's Rust API is unstable, so its component crates are pinned to the same version.
Building from source requires Rust 1.96 or newer.
Metadata
Release files for prune-source 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prune_source-0.1.6.tar.gz | 17.9 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| prune_source-0.1.6-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| prune_source-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| prune_source-0.1.6-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| prune_source-0.1.6-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| prune_source-0.1.6-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 1.3 MB
Release files / prune_source-0.1.6.tar.gz
| Download URL | prune_source-0.1.6.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c97a989a443233ef456f3e1117eb136bbbac86dbebc1aef48cd6ec29aae27176
|
|
BLAKE2b-256 checksum How to use checksums |
d6f5586c258ff0cf985cfaaf89eb9b3fc399ef8b989bd2aff9620925d6fbbede
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency logRelease files / prune_source-0.1.6-cp311-abi3-win_amd64.whl
| Download URL | prune_source-0.1.6-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 198.4 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
a1bff69c5d051ec630fef49d738db585665fa8c4b6605782c4da83861ea9ec9e
|
|
BLAKE2b-256 checksum How to use checksums |
c075fdb2870e2a8538c0e6e1392176db6d077c50719c14b9f62e9085e52cc8f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency logRelease files / prune_source-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | prune_source-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 290.7 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
71c005cbd051b30f11b63df3b11ceecabb692b2f33b634135d8a54858b3bf3e8
|
|
BLAKE2b-256 checksum How to use checksums |
ac1eb0c187d786715bdcd0a045b5e0b97089881826f42eed7325ff02b44259b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency logRelease files / prune_source-0.1.6-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | prune_source-0.1.6-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 282.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
df390920ed10f9267a3b6b6b624caadb5c4e32252c86121accdccbb95dbe72da
|
|
BLAKE2b-256 checksum How to use checksums |
36d5ded09a1629a9fa9a61370dd94a87808f112ae42d64a7d0fe3489ae301828
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency logRelease files / prune_source-0.1.6-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | prune_source-0.1.6-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 271.3 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
105ff43ef8a4b6aa79a04b7828d4f60f34832698ba571d0f7a5a1f886ceb8511
|
|
BLAKE2b-256 checksum How to use checksums |
60d93e306a5eddafb9515fabd4ce0ab8b0a0ede4119c4944a4379380c47b6884
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency logRelease files / prune_source-0.1.6-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | prune_source-0.1.6-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 277.6 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8ef3ee0d3ff84c2709cd688096c5db103376c404a96b4779854601bd59e39ecb
|
|
BLAKE2b-256 checksum How to use checksums |
d75489d15804fb3a43ad737596ed818bd3a18625193b2942763edc52cd4fe1c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
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 Oct 6, 2026.
Transparency log