Persistent Memory
Project description
skpmem - Smart Key-Value Persistent Memory
A high-performance, thread-safe persistent memory library that supports both synchronous and asynchronous operations with automatic eviction, reference counting, and background VACUUM optimization.
Installation
pip install skpmem
Features
- Synchronous and asynchronous operation support
- Automatic LRU-style eviction with reference counting
- Background VACUUM for database optimization
- Thread-safe mixed sync/async usage
- Dict-like interface for synchronous operations
- Context manager support for both paradigms
- Configurable memory limits and optimization thresholds
Quick Start
Synchronous Usage
from skpmem import PersistentMemory
# Basic synchronous usage
mem = PersistentMemory('data.db')
mem.initialize_sync()
mem['key'] = 'value'
value = mem['key']
mem.close_sync()
Asynchronous Usage
import asyncio
from skpmem import PersistentMemory
async def main():
# Using async context manager
async with PersistentMemory('data.db') as mem:
await mem.save('key', 'value')
value = await mem.load('key')
print(f"Loaded value: {value}")
asyncio.run(main())
Mixed Sync/Async Usage
import asyncio
from skpmem import PersistentMemory
async def main():
mem = PersistentMemory('data.db')
await mem.initialize()
mem.initialize_sync()
# Use both sync and async operations
mem['sync_key'] = 'sync_value'
await mem.save('async_key', 'async_value')
sync_value = mem['sync_key']
async_value = await mem.load('async_key')
await mem.close()
asyncio.run(main())
API Reference
PersistentMemory
The main class for persistent memory operations.
Methods
initialize_sync(): Initialize for synchronous operationsinitialize(): Initialize for asynchronous operations (async)save(key, value): Save data asynchronously (async)load(key, default=None): Load data asynchronously (async)close_sync(): Close synchronous connectionsclose(): Close asynchronous connections (async)
Dict-like Interface
mem[key] = value: Store value synchronouslyvalue = mem[key]: Retrieve value synchronouslydel mem[key]: Delete key synchronously
Context Manager Support
# Async context manager
async with PersistentMemory('data.db') as mem:
await mem.save('key', 'value')
# Sync context manager
with PersistentMemory('data.db').sync_context() as mem:
mem['key'] = 'value'
Advanced Features
Automatic Eviction
The library automatically manages memory usage by evicting least recently used items when memory limits are reached.
Background Optimization
Database VACUUM operations run in the background to maintain optimal performance.
Thread Safety
All operations are thread-safe, allowing mixed synchronous and asynchronous usage from multiple threads.
Requirements
- Python 3.10+
- aiosqlite
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file skpmem-0.2.0.tar.gz.
File metadata
- Download URL: skpmem-0.2.0.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed63915bb29fb577d7731d8dba781bf49d75da0809b0f856e2653e37589f9b7e
|
|
| MD5 |
d968fbd68f4e2deb0b7a26c9f9ba63f6
|
|
| BLAKE2b-256 |
9ee44bb6fb36c63de1d90bf10165f495a70d77fde3ddedc096f90b45b7cb13d1
|
File details
Details for the file skpmem-0.2.0-py3-none-any.whl.
File metadata
- Download URL: skpmem-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ca3bbdda739ef3735df95a239ec9a8b23df82a3b78fe20e6fb2c2f835a35b99
|
|
| MD5 |
02ea3a68cc9560d5b2ad8eb1a6167f27
|
|
| BLAKE2b-256 |
10354838052e7e6b27251f181bf260b9f8abb3ffec28e955f34e5a66440a36de
|