asgi-compression 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,7 +16,7 @@ def import_brotli() -> None:
16
16
  import brotli
17
17
  except ImportError as e:
18
18
  raise ImportError(
19
- "brotli is not installed, run `pip install brotli`]"
19
+ 'brotli is not installed, run `pip install "asgi-compression[br]"`'
20
20
  ) from e
21
21
 
22
22
 
File without changes
asgi_compression/zstd.py CHANGED
@@ -15,7 +15,7 @@ def import_zstandard() -> None:
15
15
  import zstandard
16
16
  except ImportError as e:
17
17
  raise ImportError(
18
- "zstandard is not installed, run `pip install zstandard`]"
18
+ 'zstandard is not installed, run `pip install "asgi-compression[zstd]"`'
19
19
  ) from e
20
20
 
21
21
 
@@ -0,0 +1,182 @@
1
+ Metadata-Version: 2.4
2
+ Name: asgi-compression
3
+ Version: 0.1.1
4
+ Summary: A framework-independent compression middleware for ASGI applications
5
+ Author-email: Serhii Shevchuk <serhii.shevchuk.dev@gmail.com>
6
+ Maintainer-email: Serhii Shevchuk <serhii.shevchuk.dev@gmail.com>
7
+ License: MIT
8
+ Project-URL: Documentation, https://github.com/serozhenka/asgi-compression
9
+ Project-URL: Issues, https://github.com/serozhenka/asgi-compression/issues
10
+ Project-URL: Source, https://github.com/serozhenka/asgi-compression
11
+ Keywords: asgi,compression,middleware,gzip,brotli,zstandard,zstd
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Web Environment
14
+ Classifier: Framework :: AsyncIO
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: Implementation :: CPython
25
+ Classifier: Topic :: Internet :: WWW/HTTP
26
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
27
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.9
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: multidict>=6.2.0
33
+ Provides-Extra: all
34
+ Requires-Dist: brotli>=1.1.0; extra == "all"
35
+ Requires-Dist: zstandard>=0.23.0; extra == "all"
36
+ Provides-Extra: br
37
+ Requires-Dist: brotli>=1.1.0; extra == "br"
38
+ Provides-Extra: zstd
39
+ Requires-Dist: zstandard>=0.23.0; extra == "zstd"
40
+ Dynamic: license-file
41
+
42
+ # ASGI Compression
43
+
44
+ A framework and platform-independent compression middleware for ASGI applications.
45
+
46
+ ## ✨ Features
47
+
48
+ - 🚀 **Framework Independent** - Works with any ASGI-compatible framework (FastAPI, Starlette, Litestar, Django, Falcon, etc.)
49
+ - 📦 **Multiple Compression Algorithms** - Supports gzip, brotli, and zstandard compression algorithms
50
+ - 🔄 **Content Negotiation** - Automatically selects the best compression algorithm based on the client's Accept-Encoding header
51
+ - 🛠️ **Fully Configurable** - Control minimum size for compression, compression levels, and more
52
+ - 📏 **Minimal Dependencies** - Single external dependency (multidict) apart from optional compression libraries
53
+ - 📝 **Fully Typed** - Complete type annotations for excellent IDE support and code safety
54
+ - 🐍 **Wide Python Support** - Compatible with Python 3.9 to 3.13
55
+ - 🔍 **Streaming Support** - Efficiently compresses both standard and streaming responses
56
+ - 🖥️ **Platform Independent** - Supports macOS, Linux, and Windows.
57
+
58
+ ## 📥 Installation
59
+
60
+ Install the package with pip:
61
+
62
+ ```bash
63
+ # Basic installation (includes gzip compression)
64
+ pip install asgi-compression
65
+
66
+ # With gzip and brotli support
67
+ pip install asgi-compression[br]
68
+
69
+ # With gzip and zstandard support
70
+ pip install asgi-compression[zstd]
71
+
72
+ # With gzip, brotli and zstandard support
73
+ pip install asgi-compression[all]
74
+ ```
75
+
76
+ ## 🚀 Usage
77
+
78
+ ### Basic Example
79
+
80
+ ```python
81
+ from asgi_compression import CompressionMiddleware, GzipAlgorithm
82
+
83
+ app = ... # Your ASGI application
84
+
85
+ # Apply gzip compression with default settings
86
+ app = CompressionMiddleware(
87
+ app=app,
88
+ algorithms=[GzipAlgorithm()],
89
+ )
90
+ ```
91
+
92
+ ### Multiple Algorithms Example
93
+
94
+ ```python
95
+ from asgi_compression import (
96
+ BrotliAlgorithm,
97
+ CompressionMiddleware,
98
+ GzipAlgorithm,
99
+ ZstdAlgorithm
100
+ )
101
+
102
+ app = ... # Your ASGI application
103
+
104
+ # Apply multiple compression algorithms in order of preference
105
+ app = CompressionMiddleware(
106
+ app=app,
107
+ algorithms=[
108
+ BrotliAlgorithm(), # Brotli will be used if the client supports it
109
+ ZstdAlgorithm(), # Zstandard will be used as a fallback
110
+ GzipAlgorithm(), # Gzip as a last resort
111
+ ],
112
+ minimum_size=1000, # Only compress responses larger than 1KB
113
+ )
114
+ ```
115
+
116
+ ### Framework-Specific Examples
117
+
118
+ #### FastAPI
119
+
120
+ ```python
121
+ from fastapi import FastAPI
122
+ from asgi_compression import CompressionMiddleware, GzipAlgorithm, BrotliAlgorithm
123
+
124
+ app = FastAPI()
125
+
126
+ @app.get("/")
127
+ async def read_root():
128
+ return {"Hello": "World"}
129
+
130
+ # Apply compression middleware
131
+ app.add_middleware(
132
+ CompressionMiddleware,
133
+ algorithms=[BrotliAlgorithm(), GzipAlgorithm()],
134
+ )
135
+ ```
136
+
137
+ #### Starlette
138
+
139
+ ```python
140
+ from starlette.applications import Starlette
141
+ from starlette.responses import JSONResponse
142
+ from starlette.routing import Route
143
+ from asgi_compression import CompressionMiddleware, GzipAlgorithm
144
+
145
+ async def homepage(request):
146
+ return JSONResponse({"hello": "world"})
147
+
148
+ routes = [
149
+ Route("/", homepage)
150
+ ]
151
+
152
+ app = Starlette(routes=routes)
153
+ app = CompressionMiddleware(app=app, algorithms=[GzipAlgorithm()])
154
+ ```
155
+
156
+ #### Litestar
157
+
158
+ ```python
159
+ from litestar import Litestar, get
160
+ from asgi_compression import CompressionMiddleware, BrotliAlgorithm
161
+
162
+ @get("/")
163
+ async def homepage() -> dict:
164
+ return {"hello": "world"}
165
+
166
+ app = Litestar(route_handlers=[homepage])
167
+ app = CompressionMiddleware(app=app, algorithms=[BrotliAlgorithm()])
168
+ ```
169
+
170
+ ## 🙌 Inspired by
171
+
172
+ This project was brought to life thanks to inspiration from:
173
+
174
+ - [Startlette's](https://github.com/encode/starlette) Gzip middleware
175
+ - [brotli-asgi](https://github.com/fullonic/brotli-asgi)
176
+ - [zstd-asgi](https://github.com/tuffnatty/zstd-asgi)
177
+
178
+ Cudos to devs & maintainers of those amazing libraries!
179
+
180
+ ## 📜 License
181
+
182
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,14 @@
1
+ asgi_compression/__init__.py,sha256=hp71J4CeuSECF52-hVS-mia_m0zcXlHV72qABNww_yY,457
2
+ asgi_compression/base.py,sha256=SmWJFT1Iy5I6Sa4_Vp2uMIr4iaQE6iq686havVoZPmQ,5145
3
+ asgi_compression/brotli.py,sha256=hH9SgvxlXxZQN6Cz8VZfqktGU2qhmOPa09KkzdSwti0,2648
4
+ asgi_compression/gzip.py,sha256=dj7kaH5_VbElH2U88oKVcNQPqKTgXl2lE6ghH5Qo0CU,1608
5
+ asgi_compression/identity.py,sha256=tIGUAXxA6YJS0KsZO8se4dlR1_q6_YJNXIBU06-AE98,692
6
+ asgi_compression/middleware.py,sha256=bbH_bdsB3MSgdSN3qMj2VjkGqeGiBGBQRclEsQ6dFHo,2737
7
+ asgi_compression/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ asgi_compression/types.py,sha256=QozTp5Ebehh-I-tv_DkZnjQJ0Z91_Mk5W8-rBI4E0rE,2087
9
+ asgi_compression/zstd.py,sha256=vY4W2RSutzDT6Ua-qEtpzXkxj_SypWlV2dPTBNeaesk,2532
10
+ asgi_compression-0.1.1.dist-info/licenses/LICENSE,sha256=At8Q6pgkvQSKYavwqV4PkaC2Y8AWRQdErZm8gYEJzXw,1082
11
+ asgi_compression-0.1.1.dist-info/METADATA,sha256=szhJfzoBSsJGMSC4kopl7NRmgBBeKQDo_Na3_777X_c,5594
12
+ asgi_compression-0.1.1.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
13
+ asgi_compression-0.1.1.dist-info/top_level.txt,sha256=ReOgAA8xTuoMxA4oROBnjJb7yoIjMe7xAB9dz_eXU0Q,17
14
+ asgi_compression-0.1.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.1)
2
+ Generator: setuptools (79.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Serhii Shevchuk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,14 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: asgi-compression
3
- Version: 0.1.0
4
- Summary: Add your description here
5
- Requires-Python: >=3.9
6
- Description-Content-Type: text/markdown
7
- Requires-Dist: multidict>=6.2.0
8
- Provides-Extra: all
9
- Requires-Dist: brotli>=1.1.0; extra == "all"
10
- Requires-Dist: zstandard>=0.23.0; extra == "all"
11
- Provides-Extra: br
12
- Requires-Dist: brotli>=1.1.0; extra == "br"
13
- Provides-Extra: zstd
14
- Requires-Dist: zstandard>=0.23.0; extra == "zstd"
@@ -1,12 +0,0 @@
1
- asgi_compression/__init__.py,sha256=hp71J4CeuSECF52-hVS-mia_m0zcXlHV72qABNww_yY,457
2
- asgi_compression/base.py,sha256=SmWJFT1Iy5I6Sa4_Vp2uMIr4iaQE6iq686havVoZPmQ,5145
3
- asgi_compression/brotli.py,sha256=e2YHx1anKJkvHgw0OoDJK_adzZ1ZKLwdrPgDjkUmoQU,2633
4
- asgi_compression/gzip.py,sha256=dj7kaH5_VbElH2U88oKVcNQPqKTgXl2lE6ghH5Qo0CU,1608
5
- asgi_compression/identity.py,sha256=tIGUAXxA6YJS0KsZO8se4dlR1_q6_YJNXIBU06-AE98,692
6
- asgi_compression/middleware.py,sha256=bbH_bdsB3MSgdSN3qMj2VjkGqeGiBGBQRclEsQ6dFHo,2737
7
- asgi_compression/types.py,sha256=QozTp5Ebehh-I-tv_DkZnjQJ0Z91_Mk5W8-rBI4E0rE,2087
8
- asgi_compression/zstd.py,sha256=HYX80EzHKy38w5ygAeEcR4Y8a4KVi1UNyns63ziAuvc,2518
9
- asgi_compression-0.1.0.dist-info/METADATA,sha256=DhbHj5rGQfMI4olwnY3vtrIuJSYq5SyXohPztAf51MI,438
10
- asgi_compression-0.1.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
11
- asgi_compression-0.1.0.dist-info/top_level.txt,sha256=ReOgAA8xTuoMxA4oROBnjJb7yoIjMe7xAB9dz_eXU0Q,17
12
- asgi_compression-0.1.0.dist-info/RECORD,,