hishel 1.0.0.dev1__tar.gz → 1.0.0.dev3__tar.gz
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.
- hishel-1.0.0.dev3/CHANGELOG.md +86 -0
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/PKG-INFO +139 -27
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/README.md +74 -5
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/__init__.py +15 -14
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/_async_cache.py +50 -37
- hishel-1.0.0.dev3/hishel/_async_httpx.py +243 -0
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/_core/_headers.py +11 -1
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/_core/_spec.py +184 -127
- hishel-1.0.0.dev3/hishel/_core/_storages/_async_base.py +71 -0
- hishel-1.0.0.dev1/hishel/_core/_async/_storages/_sqlite.py → hishel-1.0.0.dev3/hishel/_core/_storages/_async_sqlite.py +95 -132
- hishel-1.0.0.dev3/hishel/_core/_storages/_packing.py +144 -0
- hishel-1.0.0.dev3/hishel/_core/_storages/_sync_base.py +71 -0
- hishel-1.0.0.dev1/hishel/_core/_sync/_storages/_sqlite.py → hishel-1.0.0.dev3/hishel/_core/_storages/_sync_sqlite.py +95 -132
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/_core/models.py +13 -26
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/_sync_cache.py +50 -37
- hishel-1.0.0.dev3/hishel/_sync_httpx.py +243 -0
- hishel-1.0.0.dev3/hishel/_utils.py +129 -0
- hishel-1.0.0.dev3/hishel/asgi.py +400 -0
- hishel-1.0.0.dev3/hishel/fastapi.py +263 -0
- hishel-1.0.0.dev3/hishel/httpx.py +12 -0
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/requests.py +25 -17
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/pyproject.toml +11 -2
- hishel-1.0.0.dev1/CHANGELOG.md +0 -45
- hishel-1.0.0.dev1/hishel/_core/__init__.py +0 -59
- hishel-1.0.0.dev1/hishel/_core/_base/_storages/_base.py +0 -272
- hishel-1.0.0.dev1/hishel/_core/_base/_storages/_packing.py +0 -165
- hishel-1.0.0.dev1/hishel/_utils.py +0 -218
- hishel-1.0.0.dev1/hishel/httpx.py +0 -335
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/.gitignore +0 -0
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/LICENSE +0 -0
- {hishel-1.0.0.dev1 → hishel-1.0.0.dev3}/hishel/py.typed +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## 1.0.0.dev3 - 2025-10-26
|
|
6
|
+
### ♻️ Refactoring
|
|
7
|
+
- Replace pairs with entries, simplify storage API
|
|
8
|
+
- Automatically generate httpx sync integration from async
|
|
9
|
+
|
|
10
|
+
### ⚙️ Miscellaneous Tasks
|
|
11
|
+
- Simplify metadata docs
|
|
12
|
+
- Add custom integrations docs
|
|
13
|
+
- More robust compressed response caching
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug Fixes
|
|
16
|
+
- Add missing permissions into `publish.yml`
|
|
17
|
+
- Raise on consumed httpx streams, which we can't store as is (it's already decoded)
|
|
18
|
+
- Fix compressed data caching for requests
|
|
19
|
+
- Handle httpx iterable usage instead of iterator correctly
|
|
20
|
+
- Add date header for proper age calculation
|
|
21
|
+
|
|
22
|
+
### 🚀 Features
|
|
23
|
+
- Add integrations with fastapi and asgi
|
|
24
|
+
- Add blacksheep integration examples
|
|
25
|
+
- Add logging for asgi
|
|
26
|
+
|
|
27
|
+
## 1.0.0.dev2 - 2025-10-21
|
|
28
|
+
### ⚙️ Miscellaneous Tasks
|
|
29
|
+
- Remove redundant utils and tests
|
|
30
|
+
- Add import without extras check in ci
|
|
31
|
+
- Fix time travel date, explicitly specify the timezone
|
|
32
|
+
|
|
33
|
+
### 🐛 Bug Fixes
|
|
34
|
+
- Fix check for storing auth requests
|
|
35
|
+
- Don't raise an error on 3xx during revalidation
|
|
36
|
+
|
|
37
|
+
### 🚀 Features
|
|
38
|
+
- Add hishel_created_at response metadata
|
|
39
|
+
|
|
40
|
+
## 1.0.0.dev1 - 2025-10-21
|
|
41
|
+
### ⚙️ Miscellaneous Tasks
|
|
42
|
+
- Remove some redundant utils methods
|
|
43
|
+
|
|
44
|
+
### 📦 Dependencies
|
|
45
|
+
- Make httpx and async libs optional dependencies
|
|
46
|
+
- Make `anysqlite` optional dependency
|
|
47
|
+
- Install async extra with httpx
|
|
48
|
+
- Improve git-cliff
|
|
49
|
+
|
|
50
|
+
## 1.0.0.dev0 - 2025-10-19
|
|
51
|
+
### ⚙️ Miscellaneous Tasks
|
|
52
|
+
- Use mike powered versioning
|
|
53
|
+
- Improve docs versioning, deploy dev doc on ci
|
|
54
|
+
|
|
55
|
+
## 0.1.5 - 2025-10-18
|
|
56
|
+
### ⚙️ Miscellaneous Tasks
|
|
57
|
+
- Remove some redundant files from repo
|
|
58
|
+
|
|
59
|
+
### 🐛 Bug Fixes
|
|
60
|
+
- Fix some line breaks
|
|
61
|
+
|
|
62
|
+
### 🚀 Features
|
|
63
|
+
- Set chunk size to 128KB for httpx to reduce SQLite read/writes
|
|
64
|
+
- Better cache-control parsing
|
|
65
|
+
- Add close method to storages API (#384)
|
|
66
|
+
- Increase requests buffer size to 128KB, disable charset detection
|
|
67
|
+
|
|
68
|
+
## 0.1.4 - 2025-10-14
|
|
69
|
+
### ⚙️ Miscellaneous Tasks
|
|
70
|
+
- Improve CI (#369)
|
|
71
|
+
- Remove src folder (#373)
|
|
72
|
+
- Temporary remove python3.14 from CI
|
|
73
|
+
- Add sqlite tests for new storage
|
|
74
|
+
- Move some tests to beta
|
|
75
|
+
|
|
76
|
+
### 🐛 Bug Fixes
|
|
77
|
+
- Create an sqlite file in a cache folder
|
|
78
|
+
- Fix beta imports
|
|
79
|
+
|
|
80
|
+
### 🚀 Features
|
|
81
|
+
- Add support for a sans-IO API (#366)
|
|
82
|
+
- Allow already consumed streams with `CacheTransport` (#377)
|
|
83
|
+
- Add sqlite storage for beta storages
|
|
84
|
+
- Get rid of some locks from sqlite storage
|
|
85
|
+
- Better async implemetation for sqlite storage
|
|
86
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hishel
|
|
3
|
-
Version: 1.0.0.
|
|
3
|
+
Version: 1.0.0.dev3
|
|
4
4
|
Summary: Elegant HTTP Caching for Python
|
|
5
5
|
Project-URL: Homepage, https://hishel.com
|
|
6
6
|
Project-URL: Source, https://github.com/karpetrosyan/hishel
|
|
@@ -29,6 +29,8 @@ Requires-Dist: typing-extensions>=4.14.1
|
|
|
29
29
|
Provides-Extra: async
|
|
30
30
|
Requires-Dist: anyio>=4.9.0; extra == 'async'
|
|
31
31
|
Requires-Dist: anysqlite>=0.0.5; extra == 'async'
|
|
32
|
+
Provides-Extra: fastapi
|
|
33
|
+
Requires-Dist: fastapi>=0.119.1; extra == 'fastapi'
|
|
32
34
|
Provides-Extra: httpx
|
|
33
35
|
Requires-Dist: anyio>=4.9.0; extra == 'httpx'
|
|
34
36
|
Requires-Dist: anysqlite>=0.0.5; extra == 'httpx'
|
|
@@ -37,6 +39,7 @@ Provides-Extra: requests
|
|
|
37
39
|
Requires-Dist: requests>=2.32.5; extra == 'requests'
|
|
38
40
|
Description-Content-Type: text/markdown
|
|
39
41
|
|
|
42
|
+
|
|
40
43
|
<p align="center">
|
|
41
44
|
<img alt="Hishel Logo" width="350" src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/Shelkopryad_350x250_yellow.png#gh-dark-mode-only">
|
|
42
45
|
<img alt="Hishel Logo" width="350" src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/Shelkopryad_350x250_black.png#gh-light-mode-only">
|
|
@@ -73,14 +76,15 @@ Description-Content-Type: text/markdown
|
|
|
73
76
|
## ✨ Features
|
|
74
77
|
|
|
75
78
|
- 🎯 **RFC 9111 Compliant** - Fully compliant with the latest HTTP caching specification
|
|
76
|
-
- 🔌 **Easy Integration** - Drop-in support for HTTPX and
|
|
79
|
+
- 🔌 **Easy Integration** - Drop-in support for HTTPX, Requests, ASGI, FastAPI, and BlackSheep
|
|
77
80
|
- 💾 **Flexible Storage** - SQLite backend with more coming soon
|
|
78
81
|
- ⚡ **High Performance** - Efficient caching with minimal overhead
|
|
79
82
|
- 🔄 **Async & Sync** - Full support for both synchronous and asynchronous workflows
|
|
80
83
|
- 🎨 **Type Safe** - Fully typed with comprehensive type hints
|
|
81
84
|
- 🧪 **Well Tested** - Extensive test coverage and battle-tested
|
|
82
85
|
- 🎛️ **Configurable** - Fine-grained control over caching behavior
|
|
83
|
-
-
|
|
86
|
+
- � **Memory Efficient** - Streaming support prevents loading large payloads into memory
|
|
87
|
+
- 🌐 **Universal** - Works with any ASGI application (Starlette, Litestar, BlackSheep, etc.)
|
|
84
88
|
|
|
85
89
|
## 📦 Installation
|
|
86
90
|
|
|
@@ -90,19 +94,23 @@ pip install hishel
|
|
|
90
94
|
|
|
91
95
|
### Optional Dependencies
|
|
92
96
|
|
|
93
|
-
Install with specific
|
|
97
|
+
Install with specific integration support:
|
|
94
98
|
|
|
95
99
|
```bash
|
|
96
100
|
pip install hishel[httpx] # For HTTPX support
|
|
97
101
|
pip install hishel[requests] # For Requests support
|
|
102
|
+
pip install hishel[fastapi] # For FastAPI support (includes ASGI)
|
|
98
103
|
```
|
|
99
104
|
|
|
100
|
-
Or install
|
|
105
|
+
Or install multiple:
|
|
101
106
|
|
|
102
107
|
```bash
|
|
103
|
-
pip install hishel[httpx,requests]
|
|
108
|
+
pip install hishel[httpx,requests,fastapi]
|
|
104
109
|
```
|
|
105
110
|
|
|
111
|
+
> [!NOTE]
|
|
112
|
+
> ASGI middleware has no extra dependencies - it's included in the base installation.
|
|
113
|
+
|
|
106
114
|
## 🚀 Quick Start
|
|
107
115
|
|
|
108
116
|
### With HTTPX
|
|
@@ -156,6 +164,65 @@ response = session.get("https://api.example.com/data")
|
|
|
156
164
|
print(response.headers.get("X-Hishel-From-Cache")) # "True"
|
|
157
165
|
```
|
|
158
166
|
|
|
167
|
+
### With ASGI Applications
|
|
168
|
+
|
|
169
|
+
Add caching middleware to any ASGI application:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from hishel.asgi import ASGICacheMiddleware
|
|
173
|
+
|
|
174
|
+
# Wrap your ASGI app
|
|
175
|
+
app = ASGICacheMiddleware(app)
|
|
176
|
+
|
|
177
|
+
# Or configure with options
|
|
178
|
+
from hishel import AsyncSqliteStorage, CacheOptions
|
|
179
|
+
|
|
180
|
+
app = ASGICacheMiddleware(
|
|
181
|
+
app,
|
|
182
|
+
storage=AsyncSqliteStorage(),
|
|
183
|
+
cache_options=CacheOptions(shared=True)
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### With FastAPI
|
|
188
|
+
|
|
189
|
+
Add Cache-Control headers using the `cache()` dependency:
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
from fastapi import FastAPI
|
|
193
|
+
from hishel.fastapi import cache
|
|
194
|
+
|
|
195
|
+
app = FastAPI()
|
|
196
|
+
|
|
197
|
+
@app.get("/api/data", dependencies=[cache(max_age=300, public=True)])
|
|
198
|
+
async def get_data():
|
|
199
|
+
# Cache-Control: public, max-age=300
|
|
200
|
+
return {"data": "cached for 5 minutes"}
|
|
201
|
+
|
|
202
|
+
# Optionally wrap with ASGI middleware for local caching according to specified rules
|
|
203
|
+
from hishel.asgi import ASGICacheMiddleware
|
|
204
|
+
from hishel import AsyncSqliteStorage
|
|
205
|
+
|
|
206
|
+
app = ASGICacheMiddleware(app, storage=AsyncSqliteStorage())
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### With BlackSheep
|
|
210
|
+
|
|
211
|
+
Use BlackSheep's native `cache_control` decorator with Hishel's ASGI middleware:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from blacksheep import Application, get
|
|
215
|
+
from blacksheep.server.headers.cache import cache_control
|
|
216
|
+
|
|
217
|
+
app = Application()
|
|
218
|
+
|
|
219
|
+
@get("/api/data")
|
|
220
|
+
@cache_control(max_age=300, public=True)
|
|
221
|
+
async def get_data():
|
|
222
|
+
# Cache-Control: public, max-age=300
|
|
223
|
+
return {"data": "cached for 5 minutes"}
|
|
224
|
+
```
|
|
225
|
+
|
|
159
226
|
## 🎛️ Advanced Configuration
|
|
160
227
|
|
|
161
228
|
### Custom Cache Options
|
|
@@ -214,7 +281,11 @@ Comprehensive documentation is available at [https://hishel.com/dev](https://his
|
|
|
214
281
|
- [Getting Started](https://hishel.com)
|
|
215
282
|
- [HTTPX Integration](https://hishel.com/dev/integrations/httpx)
|
|
216
283
|
- [Requests Integration](https://hishel.com/dev/integrations/requests)
|
|
284
|
+
- [ASGI Integration](https://hishel.com/dev/asgi)
|
|
285
|
+
- [FastAPI Integration](https://hishel.com/dev/fastapi)
|
|
286
|
+
- [BlackSheep Integration](https://hishel.com/dev/integrations/blacksheep)
|
|
217
287
|
- [Storage Backends](https://hishel.com/dev/storages)
|
|
288
|
+
- [Request/Response Metadata](https://hishel.com/dev/metadata)
|
|
218
289
|
- [RFC 9111 Specification](https://hishel.com/dev/specification)
|
|
219
290
|
|
|
220
291
|
## 🤝 Contributing
|
|
@@ -255,44 +326,85 @@ Hishel is inspired by and builds upon the excellent work in the Python HTTP ecos
|
|
|
255
326
|
|
|
256
327
|
All notable changes to this project will be documented in this file.
|
|
257
328
|
|
|
258
|
-
## 1.0.
|
|
259
|
-
###
|
|
329
|
+
## 1.0.0.dev3 - 2025-10-26
|
|
330
|
+
### ♻️ Refactoring
|
|
331
|
+
- Replace pairs with entries, simplify storage API
|
|
332
|
+
- Automatically generate httpx sync integration from async
|
|
333
|
+
|
|
334
|
+
### ⚙️ Miscellaneous Tasks
|
|
335
|
+
- Simplify metadata docs
|
|
336
|
+
- Add custom integrations docs
|
|
337
|
+
- More robust compressed response caching
|
|
338
|
+
|
|
339
|
+
### 🐛 Bug Fixes
|
|
340
|
+
- Add missing permissions into `publish.yml`
|
|
341
|
+
- Raise on consumed httpx streams, which we can't store as is (it's already decoded)
|
|
342
|
+
- Fix compressed data caching for requests
|
|
343
|
+
- Handle httpx iterable usage instead of iterator correctly
|
|
344
|
+
- Add date header for proper age calculation
|
|
345
|
+
|
|
346
|
+
### 🚀 Features
|
|
347
|
+
- Add integrations with fastapi and asgi
|
|
348
|
+
- Add blacksheep integration examples
|
|
349
|
+
- Add logging for asgi
|
|
350
|
+
|
|
351
|
+
## 1.0.0.dev2 - 2025-10-21
|
|
352
|
+
### ⚙️ Miscellaneous Tasks
|
|
353
|
+
- Remove redundant utils and tests
|
|
354
|
+
- Add import without extras check in ci
|
|
355
|
+
- Fix time travel date, explicitly specify the timezone
|
|
356
|
+
|
|
357
|
+
### 🐛 Bug Fixes
|
|
358
|
+
- Fix check for storing auth requests
|
|
359
|
+
- Don't raise an error on 3xx during revalidation
|
|
360
|
+
|
|
361
|
+
### 🚀 Features
|
|
362
|
+
- Add hishel_created_at response metadata
|
|
363
|
+
|
|
364
|
+
## 1.0.0.dev1 - 2025-10-21
|
|
365
|
+
### ⚙️ Miscellaneous Tasks
|
|
260
366
|
- Remove some redundant utils methods
|
|
261
367
|
|
|
368
|
+
### 📦 Dependencies
|
|
369
|
+
- Make httpx and async libs optional dependencies
|
|
370
|
+
- Make `anysqlite` optional dependency
|
|
371
|
+
- Install async extra with httpx
|
|
372
|
+
- Improve git-cliff
|
|
373
|
+
|
|
262
374
|
## 1.0.0.dev0 - 2025-10-19
|
|
263
|
-
###
|
|
375
|
+
### ⚙️ Miscellaneous Tasks
|
|
264
376
|
- Use mike powered versioning
|
|
265
377
|
- Improve docs versioning, deploy dev doc on ci
|
|
266
378
|
|
|
267
379
|
## 0.1.5 - 2025-10-18
|
|
268
|
-
###
|
|
380
|
+
### ⚙️ Miscellaneous Tasks
|
|
381
|
+
- Remove some redundant files from repo
|
|
382
|
+
|
|
383
|
+
### 🐛 Bug Fixes
|
|
384
|
+
- Fix some line breaks
|
|
385
|
+
|
|
386
|
+
### 🚀 Features
|
|
269
387
|
- Set chunk size to 128KB for httpx to reduce SQLite read/writes
|
|
270
388
|
- Better cache-control parsing
|
|
271
389
|
- Add close method to storages API (#384)
|
|
272
390
|
- Increase requests buffer size to 128KB, disable charset detection
|
|
273
391
|
|
|
274
|
-
|
|
275
|
-
|
|
392
|
+
## 0.1.4 - 2025-10-14
|
|
393
|
+
### ⚙️ Miscellaneous Tasks
|
|
394
|
+
- Improve CI (#369)
|
|
395
|
+
- Remove src folder (#373)
|
|
396
|
+
- Temporary remove python3.14 from CI
|
|
397
|
+
- Add sqlite tests for new storage
|
|
398
|
+
- Move some tests to beta
|
|
276
399
|
|
|
277
|
-
###
|
|
278
|
-
-
|
|
400
|
+
### 🐛 Bug Fixes
|
|
401
|
+
- Create an sqlite file in a cache folder
|
|
402
|
+
- Fix beta imports
|
|
279
403
|
|
|
280
|
-
|
|
281
|
-
### <!-- 0 -->🚀 Features
|
|
404
|
+
### 🚀 Features
|
|
282
405
|
- Add support for a sans-IO API (#366)
|
|
283
406
|
- Allow already consumed streams with `CacheTransport` (#377)
|
|
284
407
|
- Add sqlite storage for beta storages
|
|
285
408
|
- Get rid of some locks from sqlite storage
|
|
286
409
|
- Better async implemetation for sqlite storage
|
|
287
410
|
|
|
288
|
-
### <!-- 1 -->🐛 Bug Fixes
|
|
289
|
-
- Create an sqlite file in a cache folder
|
|
290
|
-
- Fix beta imports
|
|
291
|
-
|
|
292
|
-
### <!-- 7 -->⚙️ Miscellaneous Tasks
|
|
293
|
-
- Improve CI (#369)
|
|
294
|
-
- Remove src folder (#373)
|
|
295
|
-
- Temporary remove python3.14 from CI
|
|
296
|
-
- Add sqlite tests for new storage
|
|
297
|
-
- Move some tests to beta
|
|
298
|
-
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
<p align="center">
|
|
2
3
|
<img alt="Hishel Logo" width="350" src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/Shelkopryad_350x250_yellow.png#gh-dark-mode-only">
|
|
3
4
|
<img alt="Hishel Logo" width="350" src="https://raw.githubusercontent.com/karpetrosyan/hishel/master/docs/static/Shelkopryad_350x250_black.png#gh-light-mode-only">
|
|
@@ -34,14 +35,15 @@
|
|
|
34
35
|
## ✨ Features
|
|
35
36
|
|
|
36
37
|
- 🎯 **RFC 9111 Compliant** - Fully compliant with the latest HTTP caching specification
|
|
37
|
-
- 🔌 **Easy Integration** - Drop-in support for HTTPX and
|
|
38
|
+
- 🔌 **Easy Integration** - Drop-in support for HTTPX, Requests, ASGI, FastAPI, and BlackSheep
|
|
38
39
|
- 💾 **Flexible Storage** - SQLite backend with more coming soon
|
|
39
40
|
- ⚡ **High Performance** - Efficient caching with minimal overhead
|
|
40
41
|
- 🔄 **Async & Sync** - Full support for both synchronous and asynchronous workflows
|
|
41
42
|
- 🎨 **Type Safe** - Fully typed with comprehensive type hints
|
|
42
43
|
- 🧪 **Well Tested** - Extensive test coverage and battle-tested
|
|
43
44
|
- 🎛️ **Configurable** - Fine-grained control over caching behavior
|
|
44
|
-
-
|
|
45
|
+
- � **Memory Efficient** - Streaming support prevents loading large payloads into memory
|
|
46
|
+
- 🌐 **Universal** - Works with any ASGI application (Starlette, Litestar, BlackSheep, etc.)
|
|
45
47
|
|
|
46
48
|
## 📦 Installation
|
|
47
49
|
|
|
@@ -51,19 +53,23 @@ pip install hishel
|
|
|
51
53
|
|
|
52
54
|
### Optional Dependencies
|
|
53
55
|
|
|
54
|
-
Install with specific
|
|
56
|
+
Install with specific integration support:
|
|
55
57
|
|
|
56
58
|
```bash
|
|
57
59
|
pip install hishel[httpx] # For HTTPX support
|
|
58
60
|
pip install hishel[requests] # For Requests support
|
|
61
|
+
pip install hishel[fastapi] # For FastAPI support (includes ASGI)
|
|
59
62
|
```
|
|
60
63
|
|
|
61
|
-
Or install
|
|
64
|
+
Or install multiple:
|
|
62
65
|
|
|
63
66
|
```bash
|
|
64
|
-
pip install hishel[httpx,requests]
|
|
67
|
+
pip install hishel[httpx,requests,fastapi]
|
|
65
68
|
```
|
|
66
69
|
|
|
70
|
+
> [!NOTE]
|
|
71
|
+
> ASGI middleware has no extra dependencies - it's included in the base installation.
|
|
72
|
+
|
|
67
73
|
## 🚀 Quick Start
|
|
68
74
|
|
|
69
75
|
### With HTTPX
|
|
@@ -117,6 +123,65 @@ response = session.get("https://api.example.com/data")
|
|
|
117
123
|
print(response.headers.get("X-Hishel-From-Cache")) # "True"
|
|
118
124
|
```
|
|
119
125
|
|
|
126
|
+
### With ASGI Applications
|
|
127
|
+
|
|
128
|
+
Add caching middleware to any ASGI application:
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
from hishel.asgi import ASGICacheMiddleware
|
|
132
|
+
|
|
133
|
+
# Wrap your ASGI app
|
|
134
|
+
app = ASGICacheMiddleware(app)
|
|
135
|
+
|
|
136
|
+
# Or configure with options
|
|
137
|
+
from hishel import AsyncSqliteStorage, CacheOptions
|
|
138
|
+
|
|
139
|
+
app = ASGICacheMiddleware(
|
|
140
|
+
app,
|
|
141
|
+
storage=AsyncSqliteStorage(),
|
|
142
|
+
cache_options=CacheOptions(shared=True)
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### With FastAPI
|
|
147
|
+
|
|
148
|
+
Add Cache-Control headers using the `cache()` dependency:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from fastapi import FastAPI
|
|
152
|
+
from hishel.fastapi import cache
|
|
153
|
+
|
|
154
|
+
app = FastAPI()
|
|
155
|
+
|
|
156
|
+
@app.get("/api/data", dependencies=[cache(max_age=300, public=True)])
|
|
157
|
+
async def get_data():
|
|
158
|
+
# Cache-Control: public, max-age=300
|
|
159
|
+
return {"data": "cached for 5 minutes"}
|
|
160
|
+
|
|
161
|
+
# Optionally wrap with ASGI middleware for local caching according to specified rules
|
|
162
|
+
from hishel.asgi import ASGICacheMiddleware
|
|
163
|
+
from hishel import AsyncSqliteStorage
|
|
164
|
+
|
|
165
|
+
app = ASGICacheMiddleware(app, storage=AsyncSqliteStorage())
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### With BlackSheep
|
|
169
|
+
|
|
170
|
+
Use BlackSheep's native `cache_control` decorator with Hishel's ASGI middleware:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from blacksheep import Application, get
|
|
174
|
+
from blacksheep.server.headers.cache import cache_control
|
|
175
|
+
|
|
176
|
+
app = Application()
|
|
177
|
+
|
|
178
|
+
@get("/api/data")
|
|
179
|
+
@cache_control(max_age=300, public=True)
|
|
180
|
+
async def get_data():
|
|
181
|
+
# Cache-Control: public, max-age=300
|
|
182
|
+
return {"data": "cached for 5 minutes"}
|
|
183
|
+
```
|
|
184
|
+
|
|
120
185
|
## 🎛️ Advanced Configuration
|
|
121
186
|
|
|
122
187
|
### Custom Cache Options
|
|
@@ -175,7 +240,11 @@ Comprehensive documentation is available at [https://hishel.com/dev](https://his
|
|
|
175
240
|
- [Getting Started](https://hishel.com)
|
|
176
241
|
- [HTTPX Integration](https://hishel.com/dev/integrations/httpx)
|
|
177
242
|
- [Requests Integration](https://hishel.com/dev/integrations/requests)
|
|
243
|
+
- [ASGI Integration](https://hishel.com/dev/asgi)
|
|
244
|
+
- [FastAPI Integration](https://hishel.com/dev/fastapi)
|
|
245
|
+
- [BlackSheep Integration](https://hishel.com/dev/integrations/blacksheep)
|
|
178
246
|
- [Storage Backends](https://hishel.com/dev/storages)
|
|
247
|
+
- [Request/Response Metadata](https://hishel.com/dev/metadata)
|
|
179
248
|
- [RFC 9111 Specification](https://hishel.com/dev/specification)
|
|
180
249
|
|
|
181
250
|
## 🤝 Contributing
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
from hishel._core.
|
|
2
|
-
from hishel._core.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
)
|
|
1
|
+
from hishel._core._storages._async_sqlite import AsyncSqliteStorage
|
|
2
|
+
from hishel._core._storages._async_base import AsyncBaseStorage
|
|
3
|
+
from hishel._core._storages._sync_sqlite import SyncSqliteStorage
|
|
4
|
+
from hishel._core._storages._sync_base import SyncBaseStorage
|
|
6
5
|
from hishel._core._headers import Headers as Headers
|
|
7
6
|
from hishel._core._spec import (
|
|
8
7
|
AnyState as AnyState,
|
|
@@ -11,21 +10,21 @@ from hishel._core._spec import (
|
|
|
11
10
|
CouldNotBeStored as CouldNotBeStored,
|
|
12
11
|
FromCache as FromCache,
|
|
13
12
|
IdleClient as IdleClient,
|
|
13
|
+
InvalidateEntries,
|
|
14
14
|
NeedRevalidation as NeedRevalidation,
|
|
15
15
|
NeedToBeUpdated as NeedToBeUpdated,
|
|
16
16
|
State as State,
|
|
17
17
|
StoreAndUse as StoreAndUse,
|
|
18
18
|
create_idle_state as create_idle_state,
|
|
19
19
|
)
|
|
20
|
-
from hishel._core._sync._storages._sqlite import SyncSqliteStorage
|
|
21
20
|
from hishel._core.models import (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Pair as Pair,
|
|
25
|
-
PairMeta as PairMeta,
|
|
21
|
+
Entry as Entry,
|
|
22
|
+
EntryMeta as EntryMeta,
|
|
26
23
|
Request as Request,
|
|
27
24
|
Response,
|
|
28
25
|
)
|
|
26
|
+
from hishel._async_cache import AsyncCacheProxy as AsyncCacheProxy
|
|
27
|
+
from hishel._sync_cache import SyncCacheProxy as SyncCacheProxy
|
|
29
28
|
|
|
30
29
|
__all__ = (
|
|
31
30
|
# New API
|
|
@@ -41,14 +40,13 @@ __all__ = (
|
|
|
41
40
|
"State",
|
|
42
41
|
"StoreAndUse",
|
|
43
42
|
"CouldNotBeStored",
|
|
43
|
+
"InvalidateEntries",
|
|
44
44
|
"create_idle_state",
|
|
45
45
|
## Models
|
|
46
46
|
"Request",
|
|
47
47
|
"Response",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"CompletePair",
|
|
51
|
-
"PairMeta",
|
|
48
|
+
"Entry",
|
|
49
|
+
"EntryMeta",
|
|
52
50
|
## Headers
|
|
53
51
|
"Headers",
|
|
54
52
|
## Storages
|
|
@@ -56,4 +54,7 @@ __all__ = (
|
|
|
56
54
|
"AsyncBaseStorage",
|
|
57
55
|
"SyncSqliteStorage",
|
|
58
56
|
"AsyncSqliteStorage",
|
|
57
|
+
# Proxy
|
|
58
|
+
"AsyncCacheProxy",
|
|
59
|
+
"SyncCacheProxy",
|
|
59
60
|
)
|