hishel 0.1.5__py3-none-any.whl → 1.0.0.dev0__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.
Files changed (41) hide show
  1. hishel/__init__.py +55 -53
  2. hishel/{beta/_async_cache.py → _async_cache.py} +3 -3
  3. hishel/{beta → _core}/__init__.py +6 -6
  4. hishel/{beta/_core → _core}/_async/_storages/_sqlite.py +3 -3
  5. hishel/{beta/_core → _core}/_base/_storages/_base.py +1 -1
  6. hishel/{beta/_core → _core}/_base/_storages/_packing.py +5 -5
  7. hishel/{beta/_core → _core}/_spec.py +89 -2
  8. hishel/{beta/_core → _core}/_sync/_storages/_sqlite.py +3 -3
  9. hishel/{beta/_core → _core}/models.py +1 -1
  10. hishel/{beta/_sync_cache.py → _sync_cache.py} +3 -3
  11. hishel/{beta/httpx.py → httpx.py} +6 -6
  12. hishel/{beta/requests.py → requests.py} +5 -5
  13. hishel-1.0.0.dev0.dist-info/METADATA +321 -0
  14. hishel-1.0.0.dev0.dist-info/RECORD +19 -0
  15. hishel/_async/__init__.py +0 -5
  16. hishel/_async/_client.py +0 -30
  17. hishel/_async/_mock.py +0 -43
  18. hishel/_async/_pool.py +0 -201
  19. hishel/_async/_storages.py +0 -768
  20. hishel/_async/_transports.py +0 -282
  21. hishel/_controller.py +0 -581
  22. hishel/_exceptions.py +0 -10
  23. hishel/_files.py +0 -54
  24. hishel/_headers.py +0 -215
  25. hishel/_lfu_cache.py +0 -71
  26. hishel/_lmdb_types_.pyi +0 -53
  27. hishel/_s3.py +0 -122
  28. hishel/_serializers.py +0 -329
  29. hishel/_sync/__init__.py +0 -5
  30. hishel/_sync/_client.py +0 -30
  31. hishel/_sync/_mock.py +0 -43
  32. hishel/_sync/_pool.py +0 -201
  33. hishel/_sync/_storages.py +0 -768
  34. hishel/_sync/_transports.py +0 -282
  35. hishel/_synchronization.py +0 -37
  36. hishel/beta/_core/__init__.py +0 -0
  37. hishel-0.1.5.dist-info/METADATA +0 -258
  38. hishel-0.1.5.dist-info/RECORD +0 -41
  39. /hishel/{beta/_core → _core}/_headers.py +0 -0
  40. {hishel-0.1.5.dist-info → hishel-1.0.0.dev0.dist-info}/WHEEL +0 -0
  41. {hishel-0.1.5.dist-info → hishel-1.0.0.dev0.dist-info}/licenses/LICENSE +0 -0
hishel/__init__.py CHANGED
@@ -1,57 +1,59 @@
1
- import httpx
2
-
3
- from ._async import *
4
- from ._controller import *
5
- from ._exceptions import *
6
- from ._headers import *
7
- from ._serializers import *
8
- from ._sync import *
9
- from ._lfu_cache import *
1
+ from hishel._core._async._storages._sqlite import AsyncSqliteStorage
2
+ from hishel._core._base._storages._base import (
3
+ AsyncBaseStorage as AsyncBaseStorage,
4
+ SyncBaseStorage as SyncBaseStorage,
5
+ )
6
+ from hishel._core._headers import Headers as Headers
7
+ from hishel._core._spec import (
8
+ AnyState as AnyState,
9
+ CacheMiss as CacheMiss,
10
+ CacheOptions as CacheOptions,
11
+ CouldNotBeStored as CouldNotBeStored,
12
+ FromCache as FromCache,
13
+ IdleClient as IdleClient,
14
+ NeedRevalidation as NeedRevalidation,
15
+ NeedToBeUpdated as NeedToBeUpdated,
16
+ State as State,
17
+ StoreAndUse as StoreAndUse,
18
+ create_idle_state as create_idle_state,
19
+ )
20
+ from hishel._core._sync._storages._sqlite import SyncSqliteStorage
21
+ from hishel._core.models import (
22
+ CompletePair as CompletePair,
23
+ IncompletePair as IncompletePair,
24
+ Pair as Pair,
25
+ PairMeta as PairMeta,
26
+ Request as Request,
27
+ Response,
28
+ )
10
29
 
11
30
  __all__ = (
12
- # Old API
13
- "AsyncCacheClient",
14
- "MockAsyncConnectionPool",
15
- "MockAsyncTransport",
16
- "AsyncCacheConnectionPool",
31
+ # New API
32
+ ## States
33
+ "AnyState",
34
+ "IdleClient",
35
+ "CacheMiss",
36
+ "FromCache",
37
+ "NeedRevalidation",
38
+ "AnyState",
39
+ "CacheOptions",
40
+ "NeedToBeUpdated",
41
+ "State",
42
+ "StoreAndUse",
43
+ "CouldNotBeStored",
44
+ "create_idle_state",
45
+ ## Models
46
+ "Request",
47
+ "Response",
48
+ "Pair",
49
+ "IncompletePair",
50
+ "CompletePair",
51
+ "PairMeta",
52
+ ## Headers
53
+ "Headers",
54
+ ## Storages
55
+ "SyncBaseStorage",
17
56
  "AsyncBaseStorage",
18
- "AsyncFileStorage",
19
- "AsyncInMemoryStorage",
20
- "AsyncRedisStorage",
21
- "AsyncS3Storage",
22
- "AsyncSQLiteStorage",
23
- "AsyncCacheTransport",
24
- "HEURISTICALLY_CACHEABLE_STATUS_CODES",
25
- "Controller",
26
- "CacheControlError",
27
- "ParseError",
28
- "ValidationError",
29
- "CacheControl",
30
- "Vary",
31
- "BaseSerializer",
32
- "JSONSerializer",
33
- "Metadata",
34
- "PickleSerializer",
35
- "YAMLSerializer",
36
- "clone_model",
37
- "CacheClient",
38
- "MockConnectionPool",
39
- "MockTransport",
40
- "CacheConnectionPool",
41
- "BaseStorage",
42
- "FileStorage",
43
- "InMemoryStorage",
44
- "RedisStorage",
45
- "S3Storage",
46
- "SQLiteStorage",
47
- "CacheTransport",
48
- "LFUCache",
57
+ "SyncSqliteStorage",
58
+ "AsyncSqliteStorage",
49
59
  )
50
-
51
- def install_cache() -> None: # pragma: no cover
52
- httpx.AsyncClient = AsyncCacheClient # type: ignore
53
- httpx.Client = CacheClient # type: ignore
54
-
55
-
56
- __version__ = "0.1.5"
57
-
@@ -8,7 +8,7 @@ from typing import AsyncIterator, Awaitable, Callable
8
8
 
9
9
  from typing_extensions import assert_never
10
10
 
11
- from hishel.beta import (
11
+ from hishel import (
12
12
  AnyState,
13
13
  AsyncBaseStorage,
14
14
  AsyncSqliteStorage,
@@ -24,8 +24,8 @@ from hishel.beta import (
24
24
  StoreAndUse,
25
25
  create_idle_state,
26
26
  )
27
- from hishel.beta._core._spec import InvalidatePairs, vary_headers_match
28
- from hishel.beta._core.models import CompletePair
27
+ from hishel._core._spec import InvalidatePairs, vary_headers_match
28
+ from hishel._core.models import CompletePair
29
29
 
30
30
  logger = logging.getLogger("hishel.integrations.clients")
31
31
 
@@ -1,10 +1,10 @@
1
- from hishel.beta._core._async._storages._sqlite import AsyncSqliteStorage
2
- from hishel.beta._core._base._storages._base import (
1
+ from hishel._core._async._storages._sqlite import AsyncSqliteStorage
2
+ from hishel._core._base._storages._base import (
3
3
  AsyncBaseStorage as AsyncBaseStorage,
4
4
  SyncBaseStorage as SyncBaseStorage,
5
5
  )
6
- from hishel.beta._core._headers import Headers as Headers
7
- from hishel.beta._core._spec import (
6
+ from hishel._core._headers import Headers as Headers
7
+ from hishel._core._spec import (
8
8
  AnyState as AnyState,
9
9
  CacheMiss as CacheMiss,
10
10
  CacheOptions as CacheOptions,
@@ -17,8 +17,8 @@ from hishel.beta._core._spec import (
17
17
  StoreAndUse as StoreAndUse,
18
18
  create_idle_state as create_idle_state,
19
19
  )
20
- from hishel.beta._core._sync._storages._sqlite import SyncSqliteStorage
21
- from hishel.beta._core.models import (
20
+ from hishel._core._sync._storages._sqlite import SyncSqliteStorage
21
+ from hishel._core.models import (
22
22
  CompletePair as CompletePair,
23
23
  IncompletePair as IncompletePair,
24
24
  Pair as Pair,
@@ -15,9 +15,9 @@ from typing import (
15
15
 
16
16
  import anysqlite
17
17
 
18
- from hishel.beta._core._base._storages._base import AsyncBaseStorage, ensure_cache_dict
19
- from hishel.beta._core._base._storages._packing import pack, unpack
20
- from hishel.beta._core.models import (
18
+ from hishel._core._base._storages._base import AsyncBaseStorage, ensure_cache_dict
19
+ from hishel._core._base._storages._packing import pack, unpack
20
+ from hishel._core.models import (
21
21
  CompletePair,
22
22
  IncompletePair,
23
23
  Pair,
@@ -7,7 +7,7 @@ import uuid
7
7
  from abc import ABC
8
8
  from pathlib import Path
9
9
 
10
- from hishel.beta._core.models import CompletePair, IncompletePair, Request, Response
10
+ from hishel._core.models import CompletePair, IncompletePair, Request, Response
11
11
 
12
12
 
13
13
  class SyncBaseStorage(ABC):
@@ -6,8 +6,8 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Union, overload
6
6
  import msgpack
7
7
  from typing_extensions import Literal, cast
8
8
 
9
- from hishel.beta._core._headers import Headers
10
- from hishel.beta._core.models import PairMeta, Request, Response
9
+ from hishel._core._headers import Headers
10
+ from hishel._core.models import PairMeta, Request, Response
11
11
 
12
12
 
13
13
  def filter_out_hishel_metadata(data: Mapping[str, Any]) -> dict[str, Any]:
@@ -15,7 +15,7 @@ def filter_out_hishel_metadata(data: Mapping[str, Any]) -> dict[str, Any]:
15
15
 
16
16
 
17
17
  if TYPE_CHECKING:
18
- from hishel.beta import CompletePair, IncompletePair
18
+ from hishel import CompletePair, IncompletePair
19
19
 
20
20
 
21
21
  @overload
@@ -39,7 +39,7 @@ def pack(
39
39
  /,
40
40
  kind: Literal["pair", "entry_db_key_index"],
41
41
  ) -> bytes:
42
- from hishel.beta import CompletePair, IncompletePair
42
+ from hishel import CompletePair, IncompletePair
43
43
 
44
44
  if kind == "entry_db_key_index":
45
45
  assert isinstance(value, uuid.UUID)
@@ -115,7 +115,7 @@ def unpack(
115
115
  /,
116
116
  kind: Literal["pair", "entry_db_key_index"],
117
117
  ) -> Union["CompletePair", "IncompletePair", uuid.UUID, None]:
118
- from hishel.beta import CompletePair, IncompletePair
118
+ from hishel import CompletePair, IncompletePair
119
119
 
120
120
  if value is None:
121
121
  return None
@@ -15,11 +15,11 @@ from typing import (
15
15
  Union,
16
16
  )
17
17
 
18
+ from hishel._core._headers import Headers, Range, Vary, parse_cache_control
18
19
  from hishel._utils import parse_date, partition
19
- from hishel.beta._core._headers import Headers, Range, Vary, parse_cache_control
20
20
 
21
21
  if TYPE_CHECKING:
22
- from hishel.beta import CompletePair, Request, Response
22
+ from hishel import CompletePair, Request, Response
23
23
 
24
24
 
25
25
  TState = TypeVar("TState", bound="State")
@@ -41,9 +41,96 @@ logger = logging.getLogger("hishel.core.spec")
41
41
 
42
42
  @dataclass
43
43
  class CacheOptions:
44
+ """
45
+ Configuration options for HTTP cache behavior.
46
+
47
+ These options control how the cache interprets and applies RFC 9111 caching rules.
48
+ All options have sensible defaults that follow the specification.
49
+
50
+ Attributes:
51
+ ----------
52
+ shared : bool
53
+ Determines whether the cache operates as a shared cache or private cache.
54
+
55
+ RFC 9111 Section 3.5: Authenticated Responses
56
+ https://www.rfc-editor.org/rfc/rfc9111.html#section-3.5
57
+
58
+ - Shared cache (True): Acts as a proxy, CDN, or gateway cache serving multiple users.
59
+ Must respect private directives and Authorization header restrictions.
60
+ Can use s-maxage directive instead of max-age for shared-specific freshness.
61
+
62
+ - Private cache (False): Acts as a browser or user-agent cache for a single user.
63
+ Can cache private responses and ignore s-maxage directives.
64
+
65
+ Default: True (shared cache)
66
+
67
+ Examples:
68
+ --------
69
+ >>> # Shared cache (proxy/CDN)
70
+ >>> options = CacheOptions(shared=True)
71
+
72
+ >>> # Private cache (browser)
73
+ >>> options = CacheOptions(shared=False)
74
+
75
+ supported_methods : list[str]
76
+ HTTP methods that are allowed to be cached by this cache implementation.
77
+
78
+ RFC 9111 Section 3, paragraph 2.1:
79
+ https://www.rfc-editor.org/rfc/rfc9111.html#section-3-2.1.1
80
+
81
+ "A cache MUST NOT store a response to a request unless:
82
+ - the request method is understood by the cache"
83
+
84
+ Default: ["GET", "HEAD"] (most commonly cached methods)
85
+
86
+ Examples:
87
+ --------
88
+ >>> # Default: cache GET and HEAD only
89
+ >>> options = CacheOptions()
90
+ >>> options.supported_methods
91
+ ['GET', 'HEAD']
92
+
93
+ >>> # Cache POST responses (advanced use case)
94
+ >>> options = CacheOptions(supported_methods=["GET", "HEAD", "POST"])
95
+
96
+ allow_stale : bool
97
+ Controls whether stale responses can be served without revalidation.
98
+
99
+ RFC 9111 Section 4.2.4: Serving Stale Responses
100
+ https://www.rfc-editor.org/rfc/rfc9111.html#section-4.2.4
101
+
102
+ "A cache MUST NOT generate a stale response unless it is disconnected or
103
+ doing so is explicitly permitted by the client or origin server (e.g., by
104
+ the max-stale request directive in Section 5.2.1, extension directives
105
+ such as those defined in [RFC5861], or configuration in accordance with
106
+ an out-of-band contract)."
107
+
108
+ Default: False (no stale responses)
109
+
110
+ Examples:
111
+ --------
112
+ >>> # Conservative: never serve stale
113
+ >>> options = CacheOptions(allow_stale=False)
114
+
115
+ >>> # Permissive: serve stale when allowed
116
+ >>> options = CacheOptions(allow_stale=True)
117
+
118
+ >>> # Stale-while-revalidate pattern (RFC 5861)
119
+ >>> # Even with allow_stale=True, directives are respected
120
+ >>> options = CacheOptions(allow_stale=True)
121
+ """
122
+
44
123
  shared: bool = True
124
+ """
125
+ When True, the cache operates as a shared cache (proxy/CDN).
126
+ When False, as a private cache (browser).
127
+ """
128
+
45
129
  supported_methods: list[str] = field(default_factory=lambda: ["GET", "HEAD"])
130
+ """HTTP methods that are allowed to be cached."""
131
+
46
132
  allow_stale: bool = False
133
+ """When True, stale responses can be served without revalidation."""
47
134
 
48
135
 
49
136
  @dataclass
@@ -15,9 +15,9 @@ from typing import (
15
15
 
16
16
  import sqlite3
17
17
 
18
- from hishel.beta._core._base._storages._base import SyncBaseStorage, ensure_cache_dict
19
- from hishel.beta._core._base._storages._packing import pack, unpack
20
- from hishel.beta._core.models import (
18
+ from hishel._core._base._storages._base import SyncBaseStorage, ensure_cache_dict
19
+ from hishel._core._base._storages._packing import pack, unpack
20
+ from hishel._core.models import (
21
21
  CompletePair,
22
22
  IncompletePair,
23
23
  Pair,
@@ -12,7 +12,7 @@ from typing import (
12
12
  TypedDict,
13
13
  )
14
14
 
15
- from hishel.beta._core._headers import Headers
15
+ from hishel._core._headers import Headers
16
16
 
17
17
 
18
18
  class AnyIterable:
@@ -8,7 +8,7 @@ from typing import Iterator, Awaitable, Callable
8
8
 
9
9
  from typing_extensions import assert_never
10
10
 
11
- from hishel.beta import (
11
+ from hishel import (
12
12
  AnyState,
13
13
  SyncBaseStorage,
14
14
  SyncSqliteStorage,
@@ -24,8 +24,8 @@ from hishel.beta import (
24
24
  StoreAndUse,
25
25
  create_idle_state,
26
26
  )
27
- from hishel.beta._core._spec import InvalidatePairs, vary_headers_match
28
- from hishel.beta._core.models import CompletePair
27
+ from hishel._core._spec import InvalidatePairs, vary_headers_match
28
+ from hishel._core.models import CompletePair
29
29
 
30
30
  logger = logging.getLogger("hishel.integrations.clients")
31
31
 
@@ -6,14 +6,14 @@ from typing import AsyncIterator, Iterable, Iterator, Union, overload
6
6
 
7
7
  import httpx
8
8
 
9
- from hishel.beta import Headers, Request, Response
10
- from hishel.beta._async_cache import AsyncCacheProxy
11
- from hishel.beta._core._base._storages._base import AsyncBaseStorage, SyncBaseStorage
12
- from hishel.beta._core._spec import (
9
+ from hishel import Headers, Request, Response
10
+ from hishel._async_cache import AsyncCacheProxy
11
+ from hishel._core._base._storages._base import AsyncBaseStorage, SyncBaseStorage
12
+ from hishel._core._spec import (
13
13
  CacheOptions,
14
14
  )
15
- from hishel.beta._core.models import AnyIterable
16
- from hishel.beta._sync_cache import SyncCacheProxy
15
+ from hishel._core.models import AnyIterable
16
+ from hishel._sync_cache import SyncCacheProxy
17
17
 
18
18
  SOCKET_OPTION = t.Union[
19
19
  t.Tuple[int, int, int],
@@ -5,12 +5,12 @@ from typing import Any, Iterator, Mapping, Optional, overload
5
5
 
6
6
  from typing_extensions import assert_never
7
7
 
8
+ from hishel import Headers, Request, Response as Response
9
+ from hishel._core._base._storages._base import SyncBaseStorage
10
+ from hishel._core._spec import CacheOptions
11
+ from hishel._core.models import extract_metadata_from_headers
12
+ from hishel._sync_cache import SyncCacheProxy
8
13
  from hishel._utils import snake_to_header
9
- from hishel.beta import Headers, Request, Response as Response
10
- from hishel.beta._core._base._storages._base import SyncBaseStorage
11
- from hishel.beta._core._spec import CacheOptions
12
- from hishel.beta._core.models import extract_metadata_from_headers
13
- from hishel.beta._sync_cache import SyncCacheProxy
14
14
 
15
15
  try:
16
16
  import requests