{"id":23170076,"url":"https://github.com/abhinavomprakash/py-htminify","last_synced_at":"2026-05-06T22:02:32.343Z","repository":{"id":51085492,"uuid":"367025474","full_name":"AbhinavOmprakash/py-htminify","owner":"AbhinavOmprakash","description":"HTML minifier for Python WSGI apps","archived":false,"fork":false,"pushed_at":"2021-05-27T14:58:31.000Z","size":127,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"Production","last_synced_at":"2025-04-02T02:57:06.879Z","etag":null,"topics":["django","flask","python","wsgi-middleware"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AbhinavOmprakash.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-13T11:20:00.000Z","updated_at":"2021-08-01T21:20:33.000Z","dependencies_parsed_at":"2022-09-03T13:01:20.723Z","dependency_job_id":null,"html_url":"https://github.com/AbhinavOmprakash/py-htminify","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbhinavOmprakash%2Fpy-htminify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbhinavOmprakash%2Fpy-htminify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbhinavOmprakash%2Fpy-htminify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbhinavOmprakash%2Fpy-htminify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbhinavOmprakash","download_url":"https://codeload.github.com/AbhinavOmprakash/py-htminify/tar.gz/refs/heads/Production","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261603,"owners_count":20910108,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","flask","python","wsgi-middleware"],"created_at":"2024-12-18T03:25:43.157Z","updated_at":"2026-05-06T22:02:27.303Z","avatar_url":"https://github.com/AbhinavOmprakash.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"HTMinify\n========\n\n      .. image:: https://codecov.io/gh/AbhinavOmprakash/py-htminify/branch/Production/graph/badge.svg?token=0POQLYOEY5\n    \nA lightweight HTML minifier for *all* Python web frameworks and WSGI apps.\n\n**This project is still in BETA**  \n\nFeatures\n________\n\n* Using a web framework, like django, flask, and pyramid? We got you covered.\n* 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\n* Using an encoding that is not UTF-8? Just pass an argument, and we'll take it from there. 😉   \n* Mixing Javascript and html? We'll try to minify that too, without judging you too much. (No promises though😜).\n\nInstallation\n____________\nWith pip \n\n.. code-block:: bash\n\n    $ pip install htminify\n\nWith poetry\n\n.. code-block:: bash\n\n    $ poetry add htminify\n\n\nUsage\n_____\n\n**For Django**\n\nThe middleware goes in your ``wsgi.py`` file. An example ``wsgi.py`` will look like this.\n\n.. code-block:: Python\n\n    # wsgi.py\n    import os\n\n    from django.core.wsgi import get_wsgi_application\n    from htminify.wsgi import StripWhitespaceMiddleware # add this!\n    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')\n\n    application = get_wsgi_application()\n    application = StripWhitespaceMiddleware(application) # add this too!\n    \n\n\n**For Flask**\n\nFlask provides access to its wsgi app, which you can pass as an argument to the middleware. \nYou are essentially wrapping the middleware around the wsgi application.\nAn example flask file would be like this.\n\n.. code-block:: Python\n\n    # app.py\n    from flask import Flask\n    from htminify.wsgi import StripWhitespaceMiddleware # add this!\n\n    app = Flask(__name__)\n    app.wsgi_app = StripWhitespaceMiddleware(app.wsgi_app) # add this too!\n    \n    @app.route('/')\n    def hello():\n        return \"Hello, world.\"\n\n    if __name__==\"__main__\":\n        app.run()\n\n\nNote that we are wrapping the ``app.wsgi_app`` object and not the ``app`` object.\n\n**For any other WSGI app.**\n\n\nA similar procedure can be followed to integrate the middleware with other wsgi-Python web frameworks.\nJust wrap the middleware around the wsgi app.\n\n.. code-block:: Python\n\n    # app.py\n    from htminify.wsgi import StripWhitespaceMiddleware # add this!\n    wsgi_app = StripWhitespaceMiddleware(wsgi_app) # wrap around \n    \n\n\nConfiguration\n_____________\n\n**if you don't want to minify when debug is true**\n\nYou can do something like this\n\n.. code-block:: Python\n\n    # app.py\n    if not debug:\n        wsgi_app = StripWhitespaceMiddleware(wsgi_app) \n    \n**If you're using encoding other than UTF-8**\n\nPass the encoding-type to the middleware when wrapping the app.\n\n.. code-block:: Python\n\n    # app.py\n    from htminify.wsgi import StripWhitespaceMiddleware # add this!\n    wsgi_app = StripWhitespaceMiddleware(wsgi_app, \"UTF-16\") # pass the encoding\n\n\nTODO\n____\n\n*New Features*\n\n#. Minify Json content.\n#. Add ASGI support.\n\n*Documentation*\n\n* Generate Documentation and push to read the docs.\n* Add information for contributing.\n\n*Testing*\n\n* Improve test suite for wsgi middleware.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinavomprakash%2Fpy-htminify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhinavomprakash%2Fpy-htminify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinavomprakash%2Fpy-htminify/lists"}