{"id":14065260,"url":"https://github.com/mrf345/flask_minify","last_synced_at":"2025-04-12T21:23:50.021Z","repository":{"id":32511215,"uuid":"135807227","full_name":"mrf345/flask_minify","owner":"mrf345","description":"Flask extension to minify html, js, css and less responses.","archived":false,"fork":false,"pushed_at":"2025-03-29T06:21:27.000Z","size":237,"stargazers_count":78,"open_issues_count":0,"forks_count":12,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T01:06:38.770Z","etag":null,"topics":["css","flask","html","javascript","minify"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/Flask-Minify/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mrf345.png","metadata":{"files":{"readme":"README.md","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-02T10:07:26.000Z","updated_at":"2025-03-29T06:17:59.000Z","dependencies_parsed_at":"2023-01-14T21:27:13.588Z","dependency_job_id":"f56e393d-a297-4412-ae67-50cd8d119dd2","html_url":"https://github.com/mrf345/flask_minify","commit_stats":{"total_commits":183,"total_committers":4,"mean_commits":45.75,"dds":0.09289617486338797,"last_synced_commit":"9907839cef84e7ac0001f777de6cd2b961473bed"},"previous_names":[],"tags_count":46,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrf345%2Fflask_minify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrf345%2Fflask_minify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrf345%2Fflask_minify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrf345%2Fflask_minify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrf345","download_url":"https://codeload.github.com/mrf345/flask_minify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632892,"owners_count":21136772,"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":["css","flask","html","javascript","minify"],"created_at":"2024-08-13T07:04:23.674Z","updated_at":"2025-04-12T21:23:49.993Z","avatar_url":"https://github.com/mrf345.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003ch1 align='center'\u003e flask_minify \u003c/h1\u003e\n\u003cp align='center'\u003e\n\u003ca href='https://pypi.org/project/Flask-Minify/'\u003e\n    \u003cimg src='https://img.shields.io/github/v/tag/mrf345/flask_minify' alt='Latest Release' /\u003e\n\u003c/a\u003e\n\u003ca href='https://github.com/mrf345/flask_minify/actions/workflows/ci.yml'\u003e\n  \u003cimg src='https://github.com/mrf345/flask_minify/actions/workflows/ci.yml/badge.svg'\u003e\n\u003c/a\u003e\n\u003cbr /\u003e\n\u003cimg src='https://img.shields.io/pypi/pyversions/flask_minify' alt='Supported versions' /\u003e\n\u003cbr /\u003e\n\u003ca href='https://github.com/mrf345/flask_minify/actions/workflows/ci.yml'\u003e\n  \u003cimg src='https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/mrf345/bc746d7bfe356b54fbb93b2ea5d0d2a4/raw/flask_minify__heads_master.json' alt='Coverage Percentage' /\u003e\n\u003c/a\u003e\n\u003ca href='https://github.com/PyCQA/bandit'\u003e\n  \u003cimg src='https://img.shields.io/badge/security-bandit-yellow.svg' alt='security: bandit' /\u003e\n\u003c/a\u003e\n\u003ca href='https://github.com/psf/black'\u003e\n    \u003cimg src='https://img.shields.io/badge/style-black-000000.svg' alt='Code Style Black' /\u003e\n\u003c/a\u003e\n\u003cbr /\u003e\n\u003c/p\u003e\n\n\u003ch3 align='center'\u003eFlask extension to parse and minify html, javascript, css and less.\u003c/h3\u003e\n\n## Install:\n\nWith **pip**\n\n- `pip install Flask-Minify`\n\nfor better performance (almost two times) you can use the optional [go dependency](https://pypi.org/project/tdewolff-minify/) [only Linux supported]\n\n- `pip install Flask-Minify[go]`\n\nWith **setup-tools**\n\n- `git clone https://github.com/mrf345/flask_minify.git`\n- `cd flask_minify`\n- `python setup.py install`\n\n## Setup:\n\nIn this example the  extension will minify every HTML request, unless it's explicitly bypassed.\n\n```python\nfrom flask import Flask\nfrom flask_minify import Minify\n\napp = Flask(__name__)\nMinify(app=app, html=True, js=True, cssless=True)\n```\n\nAnother approach is using **decorators**, you can set the extension to be `passive` so will only minify the decorated routes\n\n```python\nfrom flask import Flask\nfrom flask_minify import Minify, decorators as minify_decorators\n\napp = Flask(__name__)\nMinify(app=app, passive=True)\n\n@app.route('/')\n@minify_decorators.minify(html=True, js=True, cssless=True)\ndef example():\n  return '\u003ch1\u003eExample...\u003c/h1\u003e'\n```\n\n## Options:\n\n\nOption             | type     | Description\n-------------------|----------|-------------\n app               | `object` | `Flask` app instance to be passed (default: `None`)\n html              | `bool`   | minify HTML (default: `True`)\n js                | `bool`   | minify JavaScript output (default: `True`)\n cssless           | `bool`   | minify CSS or Less. (default: `True`)\n fail_safe         | `bool`   | avoid raising error while minifying (default: `True`)\n bypass            | `list`   | endpoints to bypass minifying for, supports `Regex` (default: `[]`)\n bypass_caching    | `list`   | endpoints to bypass caching for, supports `Regex` (default: `[]`)\n caching_limit     | `int`    | limit the number of cached response variations (default: `2`).\n passive           | `bool`   | disable active minifying, to use *decorators* instead (default: `False`)\n static            | `bool`   | enable minifying static files css, less and js (default: `True`)\n script_types      | `list`   | script types to limit js minification to (default: `[]`)\n parsers           | `dict`   | parsers to handle minifying specific tags, mainly for advanced customization (default: `{}`)\n go                | `bool`   | prefer go minifier, if optional go dependency is installed (default: `True`)\n\n\n#### - `bypass` and `bypass_caching`\n\n`endpoint` in this context is the name of the function decorated with `@app.route`\nso in the following example the endpoint will be `root`:\n\n```python\n@app.route('/root/\u003cid\u003e')\ndef root(id):\n    return id\n```\n\nboth options can handle regex patterns as input so for example, if you want to bypass all routes on a certain blueprint\nyou can just pass the pattern as such:\n\n```python\nMinify(app, bypass=['blueprint_name.*'])\n```\n\n#### - `caching_limit`\n\nif the option is set to `0`, we'll not cache any response, so if you want to **disable caching** just do that.\n\n\n#### - `script_types`\n\nwhen using the option include `''` (empty string) in the list to include script blocks which are missing the `type` attribute.\n\n#### - `parsers`\n\nallows passing tag specific options to the module responsible for the minification, as well as replacing the default parser with another included option or your own custom one.\n\nIn the following example will replace the default `style` (handles CSS) parser `rcssmin` with `lesscpy`:\n\n```python\nfrom flask_minify import Minify, parsers as minify_parsers\n\nparsers = {'style': minify_parsers.Lesscpy}\n\nMinify(app=app, parsers=parsers)\n```\n\nyou can override the default parser runtime options as well, as shown in the following example:\n\n```python\nfrom flask_minify import Minify, parsers as minify_parsers\n\nclass CustomCssParser(minify_parsers.Lesscpy):\n    runtime_options = {\n        **minify_parsers.Lesscpy.runtime_options,\n        \"xminify\": False,\n    }\n\nparsers = {'style': CustomCssParser}\n\nMinify(app=app, parsers=parsers)\n```\n\nthe **default** parsers are set to `{\"html\": Html, \"script\": Jsmin, \"style\": Rcssmin}` check out [the code](https://github.com/mrf345/flask_minify/blob/master/flask_minify/parsers.py) for more insight.\n\n\n## Development:\nMake sure you have [nox](https://nox.thea.codes/en/stable/) installed.\n\n- *Tests*: `nox -s test`\n- *Style check*: `nox -s lint`\n- *Format code*: `nox -s format`\n\n## Breaking changes\n\n#### `0.44`\nIntroduced more performant parsers that will be enabled by default, if you're running Linux and the optional `Go` dependency is installed [tdewolff-minify](https://pypi.org/project/tdewolff-minify/). You can disable that behavior using `minify(go=False)`.\n\n#### `0.40`\n\nDue to a future deprecation in Flask 2.3, the extension is no longer going to fallback to `Flask._app_ctx_stack`, it will raise an exception instead (`flask_minify.exceptions.MissingApp`)\n\n#### `0.33`\n\nintroduces a breaking change to the expected output, in this release `lesscpy` will be replaced by `cssmin` as\nthe default css minifier so no more `less` compiling by default. in case you don't want that, follow [this example](https://github.com/mrf345/flask_minify#--parsers). \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrf345%2Fflask_minify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrf345%2Fflask_minify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrf345%2Fflask_minify/lists"}