Skip to main content

Treeshake

Ever used a CSS framework and cried about all the overhead it caused? Ever wrote so much CSS that you were no longer aware what parts of it were actually used? Fear no more. Just use treeshake before deployment and all of your troubles will melt away.

Dead code elimination

Tree shaking is a concept mostly used in ECMAScript languages like Dart, JavaScript and Typescript that helps to eliminate unused code. Optimizing your code in a single bundle.

This project aims to bring the power of tree shaking for css to your Python projects. This small library is written in Cython and allows you to get the best performance out of your (potentially) bloated web applications.

Installation

It is recommended to install treeshake via pip:

pip install treeshake

Command Line Support

To quickly use treeshake, call it via command line:

shake <css dir> <html dir>
python3 -m treeshake <css dir> <html directory>

If you wish to see an interactive prompt, just use shake or python3 -m treeshake. The current support is only for a single directory. To see help, please run: shake -h.

Quick example

The following piece of codes recursively adds all css files from /styles/ and all html files from /html and compares the contents. Where possible, it will eliminate styling.

The new file is written to the /out/ output directory.

from treeshake import Shaker

treeshaker = Shaker()
treeshaker.discover_add_stylesheets('./styles/', True)
treeshaker.discover_add_html('./html/', True)
treeshaker.optimize('./out')

Contributing

Any contribution to this project is very welcome. Please open an issue when you are dealing with a problem or want to discuss a feature. All contributions are handled by pull requests.

Please refer to CONTRIBUTING.md for more information.

Metadata

Release files for treeshake 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for treeshake 0.3.1
File Interpreter ABI Platform
treeshake-0.3.1-cp39-cp39-macosx_11_0_x86_64.whl CPython 3.9 CPython 3.9 macOS 11.0+ x86-64 Details

Release files / treeshake-0.3.1-cp39-cp39-macosx_11_0_x86_64.whl

Download URL treeshake-0.3.1-cp39-cp39-macosx_11_0_x86_64.whl
Size 74.5 kB
Tags CPython 3.9 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
9d006d193281f364689b27559ab907e75ce67c718ec0dd1d67849f6c644b3361
BLAKE2b-256 checksum
How to use checksums
9734cd9211bb7fa0ce55981f033b6b9a26a0baa445b37785fc0e50515feeab8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.1

Security for treeshake 0.3.1

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.

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