A lightweight in-memory store in pure Python
Project description
🧠 MemPy — A Minimal In-Memory Key-Value Store
It's a simplified, Python-based in-memory key-value store inspired by Redis. It is built as an experiment to help understand the inner workings of time-based data storage, expiration logic, and common data store commands.
⚠️ Not production-ready.
✨ Features
SETwith optional timestampsGETretrieves value if not expiredDELETEremoves key manuallyINCRfor integer counters- Optional TTL (Time-To-Live) support
- Lazy expiration: expired keys are deleted on access
- Fully self-contained — no dependencies
🚀 Getting Started
Clone the repo:
git clone https://github.com/miladtsx/mempy.git
cd mempy
from mempy import MemPy
mem = MemPy()
mem.set("foo", "bar", ttl=10)
print(mem.get_value("foo"))
🧪 Example Usage
mem = MemPy()
# Basic set and get
mem.set("count", 1)
print(mem.get_value("count")) # 1
# Increment
mem.incr("count")
print(mem.get_value("count")) # 2
# TTL support
mem.set("temp", "expires soon", ttl=2)
time.sleep(3)
print(mem.get_value("temp")) # None (expired)
# Delete
mem.set("to_remove", "bye")
mem.delete("to_remove")
print(mem.get_value("to_remove")) # None
🧠 What You'll Learn
Explore:
- How Redis-like systems manage key/value storage
- TTL expiration models (lazy vs. eager deletion)
- Immutable data structures with @dataclass(frozen=True)
- Safe handling of time and conflict resolution
- Python patterns for clean design
💡 Inspiration
Inspired by the simplicity and power of Redis, this project aims to make its inner workings more accessible and learnable — one function at a time.
📝 Roadmap / Possible Extensions
[ ] Background cleaner thread for eager TTL expiration
[ ] Support for data types (sets, lists, hashes)
[ ] Persistence to disk (AOF/RDB style)
[ ] Pub/Sub model
[ ] CLI interface
Package Publishing steps
$ python install build twine
$ python3 -m build
$ python3 -m twine upload --repository pypi dist/*
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 mempy_miladtsx-0.1.1.tar.gz.
File metadata
- Download URL: mempy_miladtsx-0.1.1.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
825be2712c330698af46c0695df8d4f4ec795ed03ac3dc79ee1b348dfbe9766e
|
|
| MD5 |
9468fdb5a857cfa3012e8d69a76aee05
|
|
| BLAKE2b-256 |
5f9cd55da86e00ca28e17076e396dae29c940cd4344d3566c85e7196c1f1f93b
|
File details
Details for the file mempy_miladtsx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mempy_miladtsx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cd6ee22ea0b38b7ead59a3337e64bfdee6fb39dfe5672403a6d5116e30fcf16
|
|
| MD5 |
f3a2187657f4abf206d00c0b0fcda440
|
|
| BLAKE2b-256 |
ec2890819a831535053483d4cb8dc8255ec7fbd09df53eec0ee1da7a56ca62a5
|