ab-cache 0.1.1__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.
@@ -0,0 +1,195 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ #pdm.lock
114
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
115
+ # in version control.
116
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
117
+ .pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122
+ __pypackages__/
123
+
124
+ # Celery stuff
125
+ celerybeat-schedule
126
+ celerybeat.pid
127
+
128
+ # SageMath parsed files
129
+ *.sage.py
130
+
131
+ # Environments
132
+ .env
133
+ .venv
134
+ env/
135
+ venv/
136
+ ENV/
137
+ env.bak/
138
+ venv.bak/
139
+
140
+ # Spyder project settings
141
+ .spyderproject
142
+ .spyproject
143
+
144
+ # Rope project settings
145
+ .ropeproject
146
+
147
+ # mkdocs documentation
148
+ /site
149
+
150
+ # mypy
151
+ .mypy_cache/
152
+ .dmypy.json
153
+ dmypy.json
154
+
155
+ # Pyre type checker
156
+ .pyre/
157
+
158
+ # pytype static type analyzer
159
+ .pytype/
160
+
161
+ # Cython debug symbols
162
+ cython_debug/
163
+
164
+ # PyCharm
165
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
166
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
167
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
168
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
169
+ #.idea/
170
+
171
+ # Abstra
172
+ # Abstra is an AI-powered process automation framework.
173
+ # Ignore directories containing user credentials, local state, and settings.
174
+ # Learn more at https://abstra.io/docs
175
+ .abstra/
176
+
177
+ # Visual Studio Code
178
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
179
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
180
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
181
+ # you could uncomment the following to ignore the entire vscode folder
182
+ # .vscode/
183
+
184
+ # Ruff stuff:
185
+ .ruff_cache/
186
+
187
+ # PyPI configuration file
188
+ .pypirc
189
+
190
+ # Cursor
191
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
192
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
193
+ # refer to https://docs.cursor.com/context/ignore-files
194
+ .cursorignore
195
+ .cursorindexingignore
ab_cache-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Matthew Coulter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.4
2
+ Name: ab-cache
3
+ Version: 0.1.1
4
+ Author-email: Matthew Coulter <53892067+mattcoulter7@users.noreply.github.com>
5
+ License-File: LICENSE
6
+ Requires-Python: <4,>=3.12
7
+ Requires-Dist: ab-dependency
8
+ Requires-Dist: diskcache<6,>=5.6.3
9
+ Requires-Dist: orjson<4,>=3.11.2
10
+ Requires-Dist: pydantic<3,>=2.11.7
11
+ Requires-Dist: slugify<0.0.2,>=0.0.1
12
+ Requires-Dist: sqlmodel<0.0.25,>=0.0.24
13
+ Requires-Dist: uuid7<0.2,>=0.1.0
14
+ Provides-Extra: all
15
+ Requires-Dist: redis<7,>=6.4.0; extra == 'all'
16
+ Provides-Extra: redis-async
17
+ Requires-Dist: redis<7,>=6.4.0; extra == 'redis-async'
18
+ Provides-Extra: redis-sync
19
+ Requires-Dist: redis<7,>=6.4.0; extra == 'redis-sync'
20
+ Description-Content-Type: text/markdown
21
+
22
+ # Open Banking, Opened | Database
23
+
24
+ Database Package for Open Banking, Opened API packages.
@@ -0,0 +1,3 @@
1
+ # Open Banking, Opened | Database
2
+
3
+ Database Package for Open Banking, Opened API packages.
@@ -0,0 +1,82 @@
1
+ [build-system]
2
+ build-backend = "hatchling.build"
3
+ requires = ["hatchling"]
4
+
5
+ [dependency-groups]
6
+ dev = [
7
+ "debugpy>=1.8.14,<2",
8
+ "isort>=6.0.1,<7",
9
+ "ab-test-fixtures",
10
+ "pre-commit>=4.2.0,<5",
11
+ "pytest-asyncio>=1.0.0,<2",
12
+ "pytest-cov>=6.2.1,<7",
13
+ "pytest>=8.4.1,<9",
14
+ "ruff>=0.12.3,<0.13",
15
+ "tox>=4.27.0,<5"
16
+ ]
17
+
18
+ [project]
19
+ authors = [{email = "53892067+mattcoulter7@users.noreply.github.com", name = "Matthew Coulter"}]
20
+ dependencies = [
21
+ "diskcache>=5.6.3,<6",
22
+ "ab-dependency",
23
+ "orjson>=3.11.2,<4",
24
+ "pydantic>=2.11.7,<3",
25
+ "slugify>=0.0.1,<0.0.2",
26
+ "sqlmodel>=0.0.24,<0.0.25",
27
+ "uuid7>=0.1.0,<0.2"
28
+ ]
29
+ description = ""
30
+ name = "ab-cache"
31
+ readme = "README.md"
32
+ requires-python = ">=3.12, <4"
33
+ version = "0.1.1"
34
+
35
+ [tool.uv.sources]
36
+ ab-dependency = { git = "https://github.com/auth-broker/package-dependency", tag= "0.1.2" }
37
+ ab-test-fixtures = { git = "https://@github.com/auth-broker/package-test-fixtures", tag= "0.1.1" }
38
+
39
+ [project.optional-dependencies]
40
+ all = ["redis>=6.4.0,<7"]
41
+ redis-async = ["redis>=6.4.0,<7"]
42
+ redis-sync = ["redis>=6.4.0,<7"]
43
+
44
+ [tool.hatch.build.targets.sdist]
45
+ include = ["src/ab_core"]
46
+
47
+ [tool.hatch.build.targets.wheel]
48
+ include = ["src/ab_core"]
49
+
50
+ [tool.hatch.build.targets.wheel.sources]
51
+ "src/ab_core" = "ab_core"
52
+
53
+ [tool.pytest.ini_options]
54
+ asyncio_default_fixture_loop_scope = "session"
55
+ asyncio_mode = "auto"
56
+ markers = [
57
+ "integration: Assigns the test to the integration test suite.",
58
+ "regression: Assigns the test to the regression test suite"
59
+ ]
60
+
61
+ [tool.ruff]
62
+ line-length = 120
63
+ src = ["src"]
64
+ target-version = "py312"
65
+
66
+ [tool.ruff.lint]
67
+ exclude = [".git", ".venv", "__pycache__", "proto"]
68
+ fixable = ["ALL"]
69
+ ignore = [
70
+ "D104" # missing docstring in public package
71
+ ]
72
+ select = [
73
+ "ARG001", # unused arguments
74
+ "B", # flake8-bugbear
75
+ "C4", # flake8-comprehensions
76
+ "D", # pydocstyle (docstring checks)
77
+ "E", # pycodestyle errors
78
+ "F", # pyflakes
79
+ "I", # isort
80
+ "UP", # pyupgrade
81
+ "W" # pycodestyle warnings
82
+ ]
File without changes
@@ -0,0 +1,10 @@
1
+ from typing import Annotated, Union
2
+
3
+ from pydantic import Discriminator
4
+
5
+ from .disk import DiskCache
6
+ from .inmemory import InMemoryCache
7
+ from .redis import RedisCache
8
+ from .template import TemplateCache
9
+
10
+ Cache = Annotated[Union[RedisCache, TemplateCache, InMemoryCache, DiskCache], Discriminator("type")]
@@ -0,0 +1,134 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import (
3
+ Any,
4
+ AsyncContextManager,
5
+ ContextManager,
6
+ Generic,
7
+ Optional,
8
+ Self,
9
+ TypeVar,
10
+ )
11
+
12
+ from pydantic import BaseModel, Field
13
+
14
+ from ab_core.cache.namespace import CacheNamespace
15
+
16
+
17
+ class CacheSession(BaseModel, ABC):
18
+ namespace: CacheNamespace = Field(
19
+ default_factory=CacheNamespace,
20
+ )
21
+
22
+ @abstractmethod
23
+ def get(self, key: str): ...
24
+
25
+ @abstractmethod
26
+ def set(self, key: str, value, expiry: Optional[int] = None) -> bool: ...
27
+
28
+ @abstractmethod
29
+ def set_if_not_exists(self, key: str, value, expiry: Optional[int] = None) -> bool: ...
30
+
31
+ @abstractmethod
32
+ def delete(self, key: str) -> int: ...
33
+
34
+ @abstractmethod
35
+ def increment(
36
+ self,
37
+ key: str,
38
+ *,
39
+ increment_by: int = 1,
40
+ initial_value: Optional[int] = None,
41
+ expiry: Optional[int] = None,
42
+ ) -> int: ...
43
+
44
+ @abstractmethod
45
+ def get_keys(self, pattern: str = "*"): ...
46
+
47
+ @abstractmethod
48
+ def delete_keys(self, pattern: str = "*") -> int: ...
49
+
50
+ @abstractmethod
51
+ def get_ttl(self, key: str) -> int: ...
52
+
53
+ @abstractmethod
54
+ def expire(self, key: str, ttl: int) -> bool: ...
55
+
56
+ @abstractmethod
57
+ def close(self) -> None: ...
58
+
59
+ def __enter__(self: Self) -> Self:
60
+ return self
61
+
62
+ def __exit__(self, type_: Any, value: Any, traceback: Any) -> None:
63
+ self.close()
64
+
65
+
66
+ class CacheAsyncSession(BaseModel, ABC):
67
+ namespace: CacheNamespace = Field(
68
+ default_factory=CacheNamespace,
69
+ )
70
+
71
+ @abstractmethod
72
+ async def get(self, key: str): ...
73
+
74
+ @abstractmethod
75
+ async def set(self, key: str, value, expiry: Optional[int] = None) -> bool: ...
76
+
77
+ @abstractmethod
78
+ async def set_if_not_exists(self, key: str, value, expiry: Optional[int] = None) -> bool: ...
79
+
80
+ @abstractmethod
81
+ async def delete(self, key: str) -> int: ...
82
+
83
+ @abstractmethod
84
+ async def increment(
85
+ self,
86
+ key: str,
87
+ *,
88
+ increment_by: int = 1,
89
+ initial_value: Optional[int] = None,
90
+ expiry: Optional[int] = None,
91
+ ) -> int: ...
92
+
93
+ @abstractmethod
94
+ async def get_keys(self, pattern: str = "*"): ...
95
+
96
+ @abstractmethod
97
+ async def delete_keys(self, pattern: str = "*") -> int: ...
98
+
99
+ @abstractmethod
100
+ async def get_ttl(self, key: str) -> int: ...
101
+
102
+ @abstractmethod
103
+ async def expire(self, key: str, ttl: int) -> bool: ...
104
+
105
+ @abstractmethod
106
+ async def close(self) -> None: ...
107
+
108
+ async def __aenter__(self: Self) -> Self:
109
+ return self
110
+
111
+ async def __aexit__(self, type_: Any, value: Any, traceback: Any) -> None:
112
+ await self.close()
113
+
114
+
115
+ SYNC_SESSION = TypeVar("SYNC_SESSION", bound=CacheSession)
116
+ ASYNC_SESSION = TypeVar("ASYNC_SESSION", bound=CacheAsyncSession)
117
+
118
+
119
+ class CacheBase(BaseModel, Generic[SYNC_SESSION, ASYNC_SESSION], ABC):
120
+ namespace: CacheNamespace = Field(default_factory=CacheNamespace)
121
+
122
+ @abstractmethod
123
+ def sync_session(
124
+ self,
125
+ *,
126
+ current_session: Optional[SYNC_SESSION] = None,
127
+ ) -> ContextManager[SYNC_SESSION]: ...
128
+
129
+ @abstractmethod
130
+ async def async_session(
131
+ self,
132
+ *,
133
+ current_session: Optional[ASYNC_SESSION] = None,
134
+ ) -> AsyncContextManager[ASYNC_SESSION]: ...