{"id":15044023,"url":"https://github.com/zaczero/starlette-compress","last_synced_at":"2025-10-23T19:31:50.206Z","repository":{"id":238615303,"uuid":"796962169","full_name":"Zaczero/starlette-compress","owner":"Zaczero","description":"Compression middleware for Starlette - supporting ZStd, Brotli, and GZip","archived":false,"fork":false,"pushed_at":"2025-02-08T03:41:00.000Z","size":221,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-08T04:19:40.944Z","etag":null,"topics":["compression","fastapi","python","starlette","starlette-middleware"],"latest_commit_sha":null,"homepage":"https://pypi.org/p/starlette-compress","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Zaczero.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":"2024-05-07T00:13:26.000Z","updated_at":"2025-02-08T03:41:33.000Z","dependencies_parsed_at":"2024-12-17T17:28:42.943Z","dependency_job_id":"5fbd5851-572b-4fa5-a88c-baffd1b55084","html_url":"https://github.com/Zaczero/starlette-compress","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"e99d6bb309a0f8c571cca527e7333f1e5e397d44"},"previous_names":["zaczero/starlette-compress"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fstarlette-compress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fstarlette-compress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fstarlette-compress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Zaczero%2Fstarlette-compress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Zaczero","download_url":"https://codeload.github.com/Zaczero/starlette-compress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237882172,"owners_count":19381176,"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":["compression","fastapi","python","starlette","starlette-middleware"],"created_at":"2024-09-24T20:49:58.053Z","updated_at":"2025-10-23T19:31:50.189Z","avatar_url":"https://github.com/Zaczero.png","language":"Python","funding_links":["https://liberapay.com/Zaczero/","https://github.com/sponsors/Zaczero"],"categories":[],"sub_categories":[],"readme":"# starlette-compress\n\n[![PyPI - Python Version](https://shields.monicz.dev/pypi/pyversions/starlette-compress)](https://pypi.org/project/starlette-compress)\n[![Liberapay Patrons](https://shields.monicz.dev/liberapay/patrons/Zaczero?logo=liberapay\u0026label=Patrons)](https://liberapay.com/Zaczero/)\n[![GitHub Sponsors](https://shields.monicz.dev/github/sponsors/Zaczero?logo=github\u0026label=Sponsors\u0026color=%23db61a2)](https://github.com/sponsors/Zaczero)\n\n**starlette-compress** is a fast and simple middleware for compressing responses in [Starlette](https://www.starlette.io). It supports more compression algorithms than Starlette's built-in GZipMiddleware, and has more sensible defaults.\n\n- Python 3.9+ support\n- Python 3.14 `compression.zstd` support\n- Compatible with `asyncio` and `trio` backends\n- ZStd, Brotli, and GZip compression\n- Sensible default configuration\n- [Zero-Clause BSD](https://choosealicense.com/licenses/0bsd/) — public domain dedication\n- [Semantic Versioning](https://semver.org) compliance\n\n## Installation\n\n```sh\npip install starlette-compress\n```\n\n## Basic Usage\n\n### Starlette\n\n```py\nfrom starlette.applications import Starlette\nfrom starlette.middleware import Middleware\nfrom starlette_compress import CompressMiddleware\n\nmiddleware = [\n    Middleware(CompressMiddleware)\n]\n\napp = Starlette(routes=..., middleware=middleware)\n```\n\n### FastAPI\n\nYou can use starlette-compress with [FastAPI](https://fastapi.tiangolo.com) too:\n\n```py\nfrom fastapi import FastAPI\nfrom starlette_compress import CompressMiddleware\n\napp = FastAPI()\napp.add_middleware(CompressMiddleware)\n```\n\n## Advanced Usage\n\n### Changing Minimum Response Size\n\nControl the minimum size of the response to compress. By default, responses must be at least 500 bytes to be compressed.\n\n```py\n# Starlette\nmiddleware = [\n    Middleware(CompressMiddleware, minimum_size=1000)\n]\n\n# FastAPI\napp.add_middleware(CompressMiddleware, minimum_size=1000)\n```\n\n### Tuning Compression Levels\n\nAdjust the compression levels for each algorithm. Higher levels mean smaller files but slower compression. Default level is 4 for all algorithms.\n\n```py\n# Starlette\nmiddleware = [\n    Middleware(CompressMiddleware, zstd_level=6, brotli_quality=6, gzip_level=6)\n]\n\n# FastAPI\napp.add_middleware(CompressMiddleware, zstd_level=6, brotli_quality=6, gzip_level=6)\n```\n\n### Supporting Custom Content-Types\n\nManage the supported content-types. Unknown response types are not compressed. [Check here](https://github.com/Zaczero/starlette-compress/blob/main/starlette_compress/__init__.py) for the default configuration.\n\n```py\nfrom starlette_compress import add_compress_type, remove_compress_type\n\nadd_compress_type(\"application/my-custom-type\")\nremove_compress_type(\"application/json\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaczero%2Fstarlette-compress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaczero%2Fstarlette-compress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaczero%2Fstarlette-compress/lists"}