Python Tree Shaking
English README is under construction.
Install
pip install tree-shaking
Be noted tree-shaking requires Python >= 3.12.
Usage
Project tree (before):
# my example project
/workspace/hello-world
|= .venv
|= hello_world
|- __init__.py
|- __main__.py
|- ...
|= dist
|- pyprojet.toml
|- tree_shaking.yaml
|- ...
"tree_shaking.yaml" content:
root: .
search_paths:
- <root>/.venv/Lib/site-packages
- <root>
entries:
- <root>/hello_world/__main__.py
Create a temporary script (e.g. "build.py"), code like this:
import tree_shaking
tree_shaking.build_graph_modules("./tree_shaking.yaml")
tree_shaking.dump_tree("./tree_shaking.yaml", "./dist/minified_libs")
After running, the project tree changes:
# my example project
/workspace/hello-world
|= .venv
|= hello_world
|- __init__.py
|- __main__.py
|- ...
|= dist
|= minified_libs # updated
|= ...
|- pyprojet.toml
|- tree_shaking.yaml
|- ...
You can temporarily exclude ".venv/Lib/site-packages", and add "dist/minified_libs" to Python's sys.path (put it at the first place) to test if worked.
After testing, compress "dist/minified_libs" to zip, and compare its size with ".venv/Lib/site-packages" -- the more heavy dependencies you have, the more notable changes on size reduction.
Incremental Updates
Just rerun "build.py", outputs results to the same path as last time, tree-shaking will find the changed parts and do only necessary adding/deleting operations to the target directory.
Metadata
Release files for tree-shaking 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tree_shaking-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for tree_shaking-0.4.2-py3-none-any.whl |
Release files / tree_shaking-0.4.2-py3-none-any.whl
| Download URL | tree_shaking-0.4.2-py3-none-any.whl |
|---|---|
| Size | 32.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2c25fdad5a8f7bde1956cce6926e849241b303b0040fada45de03a2b31189a50
|
|
BLAKE2b-256 checksum How to use checksums |
c84d0d6cce4c7d5faaf13189ab4306ef24a428afe9e0475bf66485109534814d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.12 {"installer":{"name":"uv","version":"0.11.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for tree-shaking 0.4.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.