{"id":50793111,"url":"https://github.com/serozhenka/asgi-compression","last_synced_at":"2026-06-12T12:30:50.516Z","repository":{"id":288936884,"uuid":"969605229","full_name":"serozhenka/asgi-compression","owner":"serozhenka","description":"🗜️ Framework-independant compression middleware for ASGI apps, supporting Gzip, Brotli and Zstandard algorithms","archived":false,"fork":false,"pushed_at":"2025-04-21T07:02:07.000Z","size":92,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-22T05:32:30.213Z","etag":null,"topics":["asgi","brotli","compression","gzip","middleware","python","zstandard","zstd"],"latest_commit_sha":null,"homepage":"","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/serozhenka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2025-04-20T14:32:30.000Z","updated_at":"2025-07-03T12:27:16.000Z","dependencies_parsed_at":"2025-04-20T15:47:17.328Z","dependency_job_id":null,"html_url":"https://github.com/serozhenka/asgi-compression","commit_stats":null,"previous_names":["serozhenka/asgi-compression"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/serozhenka/asgi-compression","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serozhenka%2Fasgi-compression","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serozhenka%2Fasgi-compression/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serozhenka%2Fasgi-compression/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serozhenka%2Fasgi-compression/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serozhenka","download_url":"https://codeload.github.com/serozhenka/asgi-compression/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serozhenka%2Fasgi-compression/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34245217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-12T02:00:06.859Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["asgi","brotli","compression","gzip","middleware","python","zstandard","zstd"],"created_at":"2026-06-12T12:30:50.342Z","updated_at":"2026-06-12T12:30:50.501Z","avatar_url":"https://github.com/serozhenka.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ASGI Compression\n\nA framework and platform-independent compression middleware for ASGI applications.\n\n## ✨ Features\n\n- 🚀 **Framework Independent** - Works with any ASGI-compatible framework (FastAPI, Starlette, Litestar, Django, Falcon, etc.)\n- 📦 **Multiple Compression Algorithms** - Supports gzip, brotli, and zstandard compression algorithms\n- 🔄 **Content Negotiation** - Automatically selects the best compression algorithm based on the client's Accept-Encoding header\n- 🛠️ **Fully Configurable** - Control minimum size for compression, compression levels, and more\n- 📏 **Minimal Dependencies** - Single external dependency (multidict) apart from optional compression libraries\n- 📝 **Fully Typed** - Complete type annotations for excellent IDE support and code safety\n- 🐍 **Wide Python Support** - Compatible with Python 3.9 to 3.13\n- 🔍 **Streaming Support** - Efficiently compresses both standard and streaming responses\n- 🖥️ **Platform Independent** - Supports macOS, Linux, and Windows.\n\n## 📥 Installation\n\nInstall the package with pip:\n\n```bash\n# Basic installation (includes gzip compression)\npip install asgi-compression\n\n# With gzip and brotli support\npip install asgi-compression[br]\n\n# With gzip and zstandard support\npip install asgi-compression[zstd]\n\n# With gzip, brotli and zstandard support\npip install asgi-compression[all]\n```\n\n## 🚀 Usage\n\n### Basic Example\n\n```python\nfrom asgi_compression import CompressionMiddleware, GzipAlgorithm\n\napp = ...  # Your ASGI application\n\n# Apply gzip compression with default settings\napp = CompressionMiddleware(\n    app=app,\n    algorithms=[GzipAlgorithm()],\n)\n```\n\n### Multiple Algorithms Example\n\n```python\nfrom asgi_compression import (\n    BrotliAlgorithm, \n    CompressionMiddleware, \n    GzipAlgorithm, \n    ZstdAlgorithm\n)\n\napp = ...  # Your ASGI application\n\n# Apply multiple compression algorithms in order of preference\napp = CompressionMiddleware(\n    app=app,\n    algorithms=[\n        BrotliAlgorithm(),  # Brotli will be used if the client supports it\n        ZstdAlgorithm(),    # Zstandard will be used as a fallback\n        GzipAlgorithm(),    # Gzip as a last resort\n    ],\n    minimum_size=1000,      # Only compress responses larger than 1KB\n)\n```\n\n### Framework-Specific Examples\n\n#### FastAPI\n\n```python\nfrom fastapi import FastAPI\nfrom asgi_compression import CompressionMiddleware, GzipAlgorithm, BrotliAlgorithm\n\napp = FastAPI()\n\n@app.get(\"/\")\nasync def read_root():\n    return {\"Hello\": \"World\"}\n\n# Apply compression middleware\napp.add_middleware(\n    CompressionMiddleware,\n    algorithms=[BrotliAlgorithm(), GzipAlgorithm()],\n)\n```\n\n#### Starlette\n\n```python\nfrom starlette.applications import Starlette\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import Route\nfrom asgi_compression import CompressionMiddleware, GzipAlgorithm\n\nasync def homepage(request):\n    return JSONResponse({\"hello\": \"world\"})\n\nroutes = [\n    Route(\"/\", homepage)\n]\n\napp = Starlette(routes=routes)\napp = CompressionMiddleware(app=app, algorithms=[GzipAlgorithm()])\n```\n\n#### Litestar\n\n```python\nfrom litestar import Litestar, get\nfrom asgi_compression import CompressionMiddleware, BrotliAlgorithm\n\n@get(\"/\")\nasync def homepage() -\u003e dict:\n    return {\"hello\": \"world\"}\n\napp = Litestar(route_handlers=[homepage])\napp = CompressionMiddleware(app=app, algorithms=[BrotliAlgorithm()])\n```\n\n## 🙌 Inspired by\n\nThis project was brought to life thanks to inspiration from:\n\n- [Startlette's](https://github.com/encode/starlette) Gzip middleware\n- [brotli-asgi](https://github.com/fullonic/brotli-asgi)\n- [zstd-asgi](https://github.com/tuffnatty/zstd-asgi)\n\nKudos to devs \u0026 maintainers of those amazing libraries!\n\n## 📜 License\n\nThis project is licensed under the terms of the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserozhenka%2Fasgi-compression","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserozhenka%2Fasgi-compression","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserozhenka%2Fasgi-compression/lists"}