Skip to main content

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 operations
  • initialize(): Initialize for asynchronous operations (async)
  • save(key, value): Save data asynchronously (async)
  • load(key, default=None): Load data asynchronously (async)
  • close_sync(): Close synchronous connections
  • close(): Close asynchronous connections (async)

Dict-like Interface

  • mem[key] = value: Store value synchronously
  • value = mem[key]: Retrieve value synchronously
  • del 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

Metadata

Release files for skpmem 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skpmem 0.2.0
File Size Uploaded
skpmem-0.2.0.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for skpmem 0.2.0
File Interpreter ABI Platform
skpmem-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.6 kB

Release files / skpmem-0.2.0.tar.gz

Download URL skpmem-0.2.0.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ed63915bb29fb577d7731d8dba781bf49d75da0809b0f856e2653e37589f9b7e
BLAKE2b-256 checksum
How to use checksums
9ee44bb6fb36c63de1d90bf10165f495a70d77fde3ddedc096f90b45b7cb13d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release files / skpmem-0.2.0-py3-none-any.whl

Download URL skpmem-0.2.0-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ca3bbdda739ef3735df95a239ec9a8b23df82a3b78fe20e6fb2c2f835a35b99
BLAKE2b-256 checksum
How to use checksums
10354838052e7e6b27251f181bf260b9f8abb3ffec28e955f34e5a66440a36de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.1

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page