Minify python
Project description
pymini
Python minifier. Built to operate on entire libraries, persisting and supporting minification across files.
Installation
pip install pymini
Usage
pymini [options] <file>
To uglify a library, use the following options to preserve your ability to import and use the library's publicly-facing utilities.
pymini --keep-module-names --keep-global-variables <file>
Comparison
We run comparisons against the following:
- pyminify - https://github.com/dflook/python-minifier
- pyminifier - https://github.com/liftoff/pyminifier
- mnfy - https://github.com/brettcannon/mnfy (does not work on Python >3.4)
To repeat our results, run the following to setup.
pip install python-minifier
pip install setuptools==57.5.0 && pip install pyminifier # hack to get pyminifer to install
pip install mnfy # if you're running python3.4
pip install pymini # ours
Then, run the following to get mini'd versions of the sample file sample/test.py
, which comes from pyminifer
's repository.
mkdir -p out
pyminify --rename-globals --remove-literal-statements sample/test.py > out/pyminify.py
pyminifier --obfuscate sample/test.py > out/pyminifier.py
python -m mnfy sample/test.py > out/mnfy.py
uglipy sample/test.py > out/pyminiest.py
Then, run ls -lh out
. You should see the following.
total 24
-rw-r--r-- 1 alvinwan staff 414B Nov 25 01:22 pyminiest.py
-rw-r--r-- 1 alvinwan staff 602B Nov 25 01:19 pyminifier.py
-rw-r--r-- 1 alvinwan staff 490B Nov 25 01:18 pyminify.py
By comparison, the original file size was 1355B; uglipy
achieves the smallest file size, 16% smaller than pyminify
and 30% smaller than pyminifier
, improving the best possible obfuscated file size reduction from 64% to 71%. We can also test against test2.py
, which comes from pyminify
's repository.
-rw-r--r-- 1 alvinwan staff 914B Nov 25 02:09 pyminiest.py
-rw-r--r-- 1 alvinwan staff 1.4K Nov 25 01:32 pyminifier.py
-rw-r--r-- 1 alvinwan staff 977B Nov 25 01:32 pyminify.py
By comparison, the original file size was 1990B. uglipy
's file size is 6% smaller than pyminify
and 34% smaller than pyminifier
, improving the best possible obfuscated file size reduction from 51% to 54%.
Develop
Run tests using the following, from the root directory
py.test --doctest-modules
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pymini-0.1.1.tar.gz
.
File metadata
- Download URL: pymini-0.1.1.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c9ecdeba81964f9932037b511ee3663c2d6d3a4b38a0e574a8152dd6a29b0f8 |
|
MD5 | 2760e8f13a7bd5b10c69cce022af51e9 |
|
BLAKE2b-256 | d3bc877d784117ffd54fbd1b5fa12025303b60b3845ab649786e2dca5d0843c8 |
File details
Details for the file pymini-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pymini-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97afc32155ac06ade34625fa9d376f43acc4bf8e17b6dd4813bb114672eadf7e |
|
MD5 | 00d05522440d1799e71d53d209f3affd |
|
BLAKE2b-256 | 0db95a20c0aeb4e66af185f009628d82d87e40898e429f6fb41d5b60cfdfc7a8 |