memoshelve 0.1.2__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.
- memoshelve-0.1.2/LICENSE +21 -0
- memoshelve-0.1.2/PKG-INFO +139 -0
- memoshelve-0.1.2/README.md +114 -0
- memoshelve-0.1.2/pyproject.toml +32 -0
- memoshelve-0.1.2/setup.cfg +4 -0
- memoshelve-0.1.2/src/memoshelve/__init__.py +1531 -0
- memoshelve-0.1.2/src/memoshelve.egg-info/PKG-INFO +139 -0
- memoshelve-0.1.2/src/memoshelve.egg-info/SOURCES.txt +11 -0
- memoshelve-0.1.2/src/memoshelve.egg-info/dependency_links.txt +1 -0
- memoshelve-0.1.2/src/memoshelve.egg-info/requires.txt +18 -0
- memoshelve-0.1.2/src/memoshelve.egg-info/top_level.txt +1 -0
- memoshelve-0.1.2/tests/test_memoshelve.py +829 -0
- memoshelve-0.1.2/tests/test_memoshelve_integration.py +387 -0
memoshelve-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Jason Gross
|
|
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,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: memoshelve
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Project-URL: Homepage, https://github.com/jxnl/memoshelve
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/jxnl/memoshelve/issues
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Provides-Extra: robust
|
|
11
|
+
Requires-Dist: dill>=0.4.0; extra == "robust"
|
|
12
|
+
Requires-Dist: stablehash>=0.2.3; extra == "robust"
|
|
13
|
+
Requires-Dist: typing-extensions>=4.14.1; extra == "robust"
|
|
14
|
+
Provides-Extra: testing
|
|
15
|
+
Requires-Dist: numpy>=2.3.2; extra == "testing"
|
|
16
|
+
Requires-Dist: pytest>=8.4.1; extra == "testing"
|
|
17
|
+
Requires-Dist: pytest-asyncio>=1.1.0; extra == "testing"
|
|
18
|
+
Requires-Dist: memoshelve[robust]; extra == "testing"
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pre-commit>=4.2.0; extra == "dev"
|
|
21
|
+
Requires-Dist: memoshelve[testing]; extra == "dev"
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Requires-Dist: memoshelve[dev,robust,testing]; extra == "all"
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# memoshelve
|
|
27
|
+
|
|
28
|
+
A persistent memoization decorator using Python's `shelve` with two-tier caching (memory + disk).
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- Two-tier caching: in-memory + persistent disk storage
|
|
33
|
+
- Async and sync function support
|
|
34
|
+
- Cache inspection and management
|
|
35
|
+
- Optional enhanced serialization with `dill` and `stablehash`
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install memoshelve
|
|
41
|
+
|
|
42
|
+
# For enhanced serialization
|
|
43
|
+
pip install memoshelve[robust]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Basic Decorator
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from memoshelve import cache
|
|
52
|
+
|
|
53
|
+
@cache(filename="cache.db")
|
|
54
|
+
def expensive_function(x, y):
|
|
55
|
+
return x * y + 42
|
|
56
|
+
|
|
57
|
+
result = expensive_function(10, 20) # Computed and cached
|
|
58
|
+
result = expensive_function(10, 20) # Retrieved from cache
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Context Manager
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from memoshelve import memoshelve
|
|
65
|
+
|
|
66
|
+
with memoshelve(expensive_function, "cache.db") as cached_fn:
|
|
67
|
+
result = cached_fn(10, 20)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Async Functions
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
@cache(filename="async_cache.db")
|
|
74
|
+
async def async_function(data):
|
|
75
|
+
return len(data) * 42
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API
|
|
79
|
+
|
|
80
|
+
### Cache Methods
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
@cache(filename="example.db")
|
|
84
|
+
def compute(x, y):
|
|
85
|
+
return x ** y
|
|
86
|
+
|
|
87
|
+
# Check if cached
|
|
88
|
+
compute.__contains__(2, 3)
|
|
89
|
+
|
|
90
|
+
# Get without computing
|
|
91
|
+
compute.get(2, 3) # Raises KeyError if not cached
|
|
92
|
+
|
|
93
|
+
# Get with status
|
|
94
|
+
result, status = compute.__call_with_status__(2, 3)
|
|
95
|
+
# status: "cached (mem)", "cached (disk)", or "miss"
|
|
96
|
+
|
|
97
|
+
# Manual operations
|
|
98
|
+
compute.put(2, 3, 8) # Store value
|
|
99
|
+
compute.uncache(2, 3) # Remove from cache
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Configuration
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
@cache(
|
|
106
|
+
filename="cache.db",
|
|
107
|
+
ignore=["debug"], # Ignore parameters in cache key
|
|
108
|
+
get_hash=custom_hash, # Custom hash function
|
|
109
|
+
disable=False, # Toggle caching
|
|
110
|
+
print_cache_miss=True, # Log cache misses
|
|
111
|
+
)
|
|
112
|
+
def my_function(data, debug=False):
|
|
113
|
+
return process(data)
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Cache Management
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from memoshelve import compact
|
|
120
|
+
|
|
121
|
+
# Compact cache file
|
|
122
|
+
compact("cache.db", backup=True)
|
|
123
|
+
|
|
124
|
+
# Access metadata
|
|
125
|
+
metadata = my_function.memoshelve
|
|
126
|
+
metadata.disk_keys() # Keys in disk cache
|
|
127
|
+
metadata.mem_keys() # Keys in memory cache
|
|
128
|
+
metadata.compact() # Compact this cache
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Storage
|
|
132
|
+
|
|
133
|
+
Default cache location: `~/.cache/memoshelve/` (configurable via `XDG_CACHE_HOME`)
|
|
134
|
+
|
|
135
|
+
Cache files use Python's `shelve` module and may create multiple files (`.db`, `.dir`, `.dat`).
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT License
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# memoshelve
|
|
2
|
+
|
|
3
|
+
A persistent memoization decorator using Python's `shelve` with two-tier caching (memory + disk).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Two-tier caching: in-memory + persistent disk storage
|
|
8
|
+
- Async and sync function support
|
|
9
|
+
- Cache inspection and management
|
|
10
|
+
- Optional enhanced serialization with `dill` and `stablehash`
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install memoshelve
|
|
16
|
+
|
|
17
|
+
# For enhanced serialization
|
|
18
|
+
pip install memoshelve[robust]
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Basic Decorator
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from memoshelve import cache
|
|
27
|
+
|
|
28
|
+
@cache(filename="cache.db")
|
|
29
|
+
def expensive_function(x, y):
|
|
30
|
+
return x * y + 42
|
|
31
|
+
|
|
32
|
+
result = expensive_function(10, 20) # Computed and cached
|
|
33
|
+
result = expensive_function(10, 20) # Retrieved from cache
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Context Manager
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from memoshelve import memoshelve
|
|
40
|
+
|
|
41
|
+
with memoshelve(expensive_function, "cache.db") as cached_fn:
|
|
42
|
+
result = cached_fn(10, 20)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Async Functions
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
@cache(filename="async_cache.db")
|
|
49
|
+
async def async_function(data):
|
|
50
|
+
return len(data) * 42
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### Cache Methods
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
@cache(filename="example.db")
|
|
59
|
+
def compute(x, y):
|
|
60
|
+
return x ** y
|
|
61
|
+
|
|
62
|
+
# Check if cached
|
|
63
|
+
compute.__contains__(2, 3)
|
|
64
|
+
|
|
65
|
+
# Get without computing
|
|
66
|
+
compute.get(2, 3) # Raises KeyError if not cached
|
|
67
|
+
|
|
68
|
+
# Get with status
|
|
69
|
+
result, status = compute.__call_with_status__(2, 3)
|
|
70
|
+
# status: "cached (mem)", "cached (disk)", or "miss"
|
|
71
|
+
|
|
72
|
+
# Manual operations
|
|
73
|
+
compute.put(2, 3, 8) # Store value
|
|
74
|
+
compute.uncache(2, 3) # Remove from cache
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Configuration
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
@cache(
|
|
81
|
+
filename="cache.db",
|
|
82
|
+
ignore=["debug"], # Ignore parameters in cache key
|
|
83
|
+
get_hash=custom_hash, # Custom hash function
|
|
84
|
+
disable=False, # Toggle caching
|
|
85
|
+
print_cache_miss=True, # Log cache misses
|
|
86
|
+
)
|
|
87
|
+
def my_function(data, debug=False):
|
|
88
|
+
return process(data)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Cache Management
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from memoshelve import compact
|
|
95
|
+
|
|
96
|
+
# Compact cache file
|
|
97
|
+
compact("cache.db", backup=True)
|
|
98
|
+
|
|
99
|
+
# Access metadata
|
|
100
|
+
metadata = my_function.memoshelve
|
|
101
|
+
metadata.disk_keys() # Keys in disk cache
|
|
102
|
+
metadata.mem_keys() # Keys in memory cache
|
|
103
|
+
metadata.compact() # Compact this cache
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Storage
|
|
107
|
+
|
|
108
|
+
Default cache location: `~/.cache/memoshelve/` (configurable via `XDG_CACHE_HOME`)
|
|
109
|
+
|
|
110
|
+
Cache files use Python's `shelve` module and may create multiple files (`.db`, `.dir`, `.dat`).
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT License
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "memoshelve"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "Add your description here"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
dependencies = []
|
|
8
|
+
|
|
9
|
+
[project.optional-dependencies]
|
|
10
|
+
# n.b. typing-extensions is required for stablehash, but not declared, cf https://github.com/NiklasRosenstein/python-stablehash/issues/9
|
|
11
|
+
robust = ["dill>=0.4.0", "stablehash>=0.2.3", "typing-extensions>=4.14.1"]
|
|
12
|
+
testing = [
|
|
13
|
+
"numpy>=2.3.2",
|
|
14
|
+
"pytest>=8.4.1",
|
|
15
|
+
"pytest-asyncio>=1.1.0",
|
|
16
|
+
"memoshelve[robust]",
|
|
17
|
+
]
|
|
18
|
+
dev = ["pre-commit>=4.2.0", "memoshelve[testing]"]
|
|
19
|
+
all = ["memoshelve[robust,testing,dev]"]
|
|
20
|
+
|
|
21
|
+
[tool.setuptools]
|
|
22
|
+
package-dir = { "" = "src" }
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
"Homepage" = "https://github.com/jxnl/memoshelve"
|
|
26
|
+
"Bug Tracker" = "https://github.com/jxnl/memoshelve/issues"
|
|
27
|
+
|
|
28
|
+
[[tool.uv.index]]
|
|
29
|
+
name = "testpypi"
|
|
30
|
+
url = "https://test.pypi.org/simple/"
|
|
31
|
+
publish-url = "https://test.pypi.org/legacy/"
|
|
32
|
+
explicit = true
|