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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48ac4438cf851b1d3b90d64fd626845517dea774ba36fcbec4f686e5f3449351
|
|
| MD5 |
6c00a269f046717736030c235eb9fa5f
|
|
| BLAKE2b-256 |
123f60593979053da1290f4bc77b559b517dbe60bed6c2c5f15319ac6b9d6e70
|
Provenance
The following attestation bundles were made for prune_source-0.1.4.tar.gz:
Publisher:
release.yml on pawamoy/prune-source
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4.tar.gz -
Subject digest:
48ac4438cf851b1d3b90d64fd626845517dea774ba36fcbec4f686e5f3449351 - Sigstore transparency entry: 2766991892
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1f6c43d244f817bb690cd618254e986686a6fc3abef0bb0af002ae276777b45
|
|
| MD5 |
20b12d38aadc67b663fa99f291efbce5
|
|
| BLAKE2b-256 |
aa1bd347762fac66f0e796c26fc126e379c71dcc3544e2cf401b5d56aaf84e97
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4-cp310-abi3-win_amd64.whl -
Subject digest:
c1f6c43d244f817bb690cd618254e986686a6fc3abef0bb0af002ae276777b45 - Sigstore transparency entry: 2766991580
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c699930131071dac00649ad27a35e6515d7b93dba84670b44bfbbd3553da229
|
|
| MD5 |
d756aaaf12844989d6b4ea02fd9313b9
|
|
| BLAKE2b-256 |
4c4aa93058e71997787599066984e89aaf2116f249b52470318023da3ed2dfeb
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
9c699930131071dac00649ad27a35e6515d7b93dba84670b44bfbbd3553da229 - Sigstore transparency entry: 2766991670
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8b932010697d51fb0e9a5f6620481af3123b7757e096c0caeedfa37fa1c6a02
|
|
| MD5 |
3a38c85bc87bda7d65c30097206af5a6
|
|
| BLAKE2b-256 |
73d596079410354109389b71dea9c4260806c316a19e731fc1162975dc97940c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
b8b932010697d51fb0e9a5f6620481af3123b7757e096c0caeedfa37fa1c6a02 - Sigstore transparency entry: 2766991810
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
631fb4ce4e5d99aaa4c20645baba9281dd5b1d6a49625510f8b6cdf100fe4bf5
|
|
| MD5 |
e2f83d7d674da28e2186bdff6ffa39cc
|
|
| BLAKE2b-256 |
d52701464f47090669c03a6a85eb6b7da1d5ec889cc8437224c9fb75bb0b5637
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4-cp310-abi3-macosx_11_0_arm64.whl -
Subject digest:
631fb4ce4e5d99aaa4c20645baba9281dd5b1d6a49625510f8b6cdf100fe4bf5 - Sigstore transparency entry: 2766991489
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8e7af5de012bc272b68025cc5aaa779eea2d96b9a8387f1ffb4eeb4838394ef
|
|
| MD5 |
10f669948d37663c9f17108752478fae
|
|
| BLAKE2b-256 |
87853aa8695d2cbaa3e7a9bbfb6d5724acef3c9ea75d18d2b78ea1903304838e
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
prune_source-0.1.4-cp310-abi3-macosx_10_12_x86_64.whl -
Subject digest:
e8e7af5de012bc272b68025cc5aaa779eea2d96b9a8387f1ffb4eeb4838394ef - Sigstore transparency entry: 2766991758
- Sigstore integration time:
-
Permalink:
pawamoy/prune-source@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Branch / Tag:
refs/tags/0.1.4 - Owner: https://github.com/pawamoy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@071d227ac8cd58f447d66872b7b18f9d7bbf939b -
Trigger Event:
push
-
Statement type: