Skip to main content

A lightweight HTML minifier for all Python web frameworks and WSGI apps.

Features

  • Using a web framework, like django, flask, and pyramid? We got you covered.

  • Or you’re feeling adventurous and you’re building your own wsgi app? We got you covered there too. This will work with any program that complies with the WSGI specification

  • Using an encoding that is not UTF-8? Just pass an argument,and we’ll take it from there. 😉

  • Mixing Javascript and html? We’ll try to minify that too, without judging you too much. (No promises though😜).

  • No external dependencies.

Installation

With pip

$ pip install htminify

With poetry

$ poetry add htminify

Usage

For Django

The middleware goes in your wsgi.py file. An example wsgi.py will look like this.

# wsgi.py
import os

from django.core.wsgi import get_wsgi_application
from htminify.wsgi import StripWhitespaceMiddleware # add this!
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')

application = get_wsgi_application()
application = StripWhitespaceMiddleware(application) # add this too!

For Flask

Flask provides access to its wsgi app, which you can pass as an argument to the middleware. You are essentially wrapping the middleware around the wsgi application. An example flask file would be like this.

# app.py
from flask import Flask
from htminify.wsgi import StripWhitespaceMiddleware # add this!

app = Flask(__name__)
app.wsgi_app = StripWhitespaceMiddleware(app.wsgi_app) # add this too!

@app.route('/')
def hello():
    return "Hello, world."

if __name__=="__main__":
    app.run()

Note that we are wrapping the app.wsgi_app object and not the app object.

For any other wsgi framework

A similar procedure can be followed to integrate the middleware with other wsgi-Python web frameworks. Just wrap the middleware around the wsgi app.

# app.py
from htminify.wsgi import StripWhitespaceMiddleware # add this!
wsgi_app = StripWhitespaceMiddleware(wsgi_app) # wrap around

Configuration

if you don’t want to minify when debug is true

You can do something like this

# app.py
if not debug:
    wsgi_app = StripWhitespaceMiddleware(wsgi_app)

If you’re using encoding other than UTF-8

Pass the encoding-type to the middleware when wrapping the app.

# app.py
from htminify.wsgi import StripWhitespaceMiddleware # add this!
wsgi_app = StripWhitespaceMiddleware(wsgi_app, "UTF-16") # pass the encoding

TODO

New Features

  1. Minify Json content.

  2. Add ASGI support.

Documentation

  • Generate Documentation and push to read the docs.

  • Add information for contributing.

Testing

  • Improve test suite for wsgi middleware.

Metadata

Release files for htminify 0.1.2

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

Source distribution (sdist)

Source distribution for htminify 0.1.2
File Size Uploaded
htminify-0.1.2.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for htminify 0.1.2
File Interpreter ABI Platform
htminify-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / htminify-0.1.2.tar.gz

Download URL htminify-0.1.2.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6f3bd5ea631010316e2457f896e2854fd8fdcb9332d855bcf91c961871b9ff8c
BLAKE2b-256 checksum
How to use checksums
e144f13d2f296afa98deca2a6d53a36ea1b27d0a2bf638914cd4339bd0e587f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.9 Windows/10

Release files / htminify-0.1.2-py3-none-any.whl

Download URL htminify-0.1.2-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c53c577a4c20045f592a221f7481c8af21fd31cde6c07e9ce99bc2d4e27da59d
BLAKE2b-256 checksum
How to use checksums
cd99de1b110c20730b9e8477dfddfc7a1043ee7840d587e6b5d14354444fe12d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.8.9 Windows/10

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

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