Skip to main content

Remove unused css in Python projects with C-powered tree shaking.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treeshake-0.2.2.tar.gz (94.1 kB view details)

Uploaded Source

Built Distribution

treeshake-0.2.2-cp39-cp39-macosx_11_0_x86_64.whl (105.9 kB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

File details

Details for the file treeshake-0.2.2.tar.gz.

File metadata

  • Download URL: treeshake-0.2.2.tar.gz
  • Upload date:
  • Size: 94.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for treeshake-0.2.2.tar.gz
Algorithm Hash digest
SHA256 612419d858e1dd91578d96a797671f8329fba4677f7b34d771a942598e4c13d3
MD5 dbfe40b85bdfdb0f3333d806371935a8
BLAKE2b-256 1bd57bb05ad2ed8e09fd58472d8a8d62a951457fffd313b232fef5e32f5f2edd

See more details on using hashes here.

File details

Details for the file treeshake-0.2.2-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

  • Download URL: treeshake-0.2.2-cp39-cp39-macosx_11_0_x86_64.whl
  • Upload date:
  • Size: 105.9 kB
  • Tags: CPython 3.9, macOS 11.0+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1

File hashes

Hashes for treeshake-0.2.2-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 3954238106aad327a82ab230e2395a651c9cdb8bd4888da0d7f5f458884647d9
MD5 ac7a251e33fd1538a31ec3a854a6f371
BLAKE2b-256 bb8b3ffea32411dddfc74c9bc185afaaad5df004a13a02cac4fa5d8df9d3bd73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page