Skip to content

Commit 3b3def3

Browse files
strawgategithub-actions[bot]claude
authored
Add FileTreeStore (#223)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: William Easton <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 432e9e4 commit 3b3def3

File tree

8 files changed

+590
-4
lines changed

8 files changed

+590
-4
lines changed

docs/api/stores.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ Persistent disk-based key-value store using DiskCache.
2323
members:
2424
- __init__
2525

26+
## FileTree Store
27+
28+
Directory-based store for visual inspection and testing.
29+
30+
::: key_value.aio.stores.filetree.FileTreeStore
31+
options:
32+
show_source: false
33+
members:
34+
- __init__
35+
2636
## Redis Store
2737

2838
Redis-backed key-value store.

docs/stores.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Local stores are stored in memory or on disk, local to the application.
3434
| Memory | N/A ||| Fast in-memory storage for development and caching |
3535
| Disk | Stable | ☑️ || Persistent file-based storage in a single file |
3636
| Disk (Per-Collection) | Stable | ☑️ || Persistent storage with separate files per collection |
37+
| FileTree (test) | Unstable | ☑️ || Directory-based storage with JSON files for visual inspection |
3738
| Null (test) | N/A ||| No-op store for testing without side effects |
3839
| RocksDB | Unstable | ☑️ || High-performance embedded database |
3940
| Simple (test) | N/A ||| Simple in-memory store for testing |
@@ -140,6 +141,74 @@ pip install py-key-value-aio[disk]
140141

141142
---
142143

144+
### FileTreeStore
145+
146+
Directory-based storage for visual inspection and debugging.
147+
148+
```python
149+
from key_value.aio.stores.filetree import FileTreeStore
150+
151+
store = FileTreeStore(directory="./debug-store")
152+
```
153+
154+
**Installation:**
155+
156+
```bash
157+
pip install py-key-value-aio[filetree]
158+
```
159+
160+
**Use Cases:**
161+
162+
- Visual inspection of store contents
163+
- Debugging store behavior
164+
- Development and testing
165+
- Understanding data structure
166+
167+
**Characteristics:**
168+
169+
- Collections as directories
170+
- Keys as JSON files (`{key}.json`)
171+
- Human-readable filesystem layout
172+
- Easy to inspect and modify
173+
- **NOT for production use**
174+
175+
**Directory Structure:**
176+
177+
```text
178+
{base_directory}/
179+
{collection_1}/
180+
{key_1}.json
181+
{key_2}.json
182+
{collection_2}/
183+
{key_3}.json
184+
```
185+
186+
**Important Limitations:**
187+
188+
- Poor performance with many keys
189+
- No atomic operations
190+
- No automatic cleanup of expired entries
191+
- Filesystem path length constraints
192+
- Subject to filesystem limitations
193+
194+
**When to Use:**
195+
196+
Use FileTreeStore when you need to:
197+
198+
- Visually inspect what's being stored
199+
- Debug complex data structures
200+
- Understand how the store organizes data
201+
- Manually modify stored data for testing
202+
203+
**When NOT to Use:**
204+
205+
- Production environments
206+
- High-performance requirements
207+
- Large datasets
208+
- Concurrent access scenarios
209+
210+
---
211+
143212
### RocksDBStore
144213

145214
High-performance embedded database using RocksDB.

key-value/key-value-aio/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ py-key-value-shared-test = { workspace = true }
3434
[project.optional-dependencies]
3535
memory = ["cachetools>=5.0.0"]
3636
disk = ["diskcache>=5.0.0", "pathvalidate>=3.3.1",]
37+
filetree = ["aiofile>=3.5.0", "anyio>=4.4.0"]
3738
redis = ["redis>=4.3.0"]
3839
mongodb = ["pymongo>=4.0.0"]
3940
valkey = ["valkey-glide>=2.1.0"]
@@ -67,7 +68,7 @@ env_files = [".env"]
6768

6869
[dependency-groups]
6970
dev = [
70-
"py-key-value-aio[memory,disk,redis,elasticsearch,memcached,mongodb,vault,dynamodb,rocksdb]",
71+
"py-key-value-aio[memory,disk,filetree,redis,elasticsearch,memcached,mongodb,vault,dynamodb,rocksdb]",
7172
"py-key-value-aio[valkey]; platform_system != 'Windows'",
7273
"py-key-value-aio[keyring]",
7374
"py-key-value-aio[pydantic]",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""File-tree based store for visual inspection and testing."""
2+
3+
from key_value.aio.stores.filetree.store import (
4+
FileTreeStore,
5+
FileTreeV1CollectionSanitizationStrategy,
6+
FileTreeV1KeySanitizationStrategy,
7+
)
8+
9+
__all__ = [
10+
"FileTreeStore",
11+
"FileTreeV1CollectionSanitizationStrategy",
12+
"FileTreeV1KeySanitizationStrategy",
13+
]

0 commit comments

Comments
 (0)