This project has been archived by its maintainers, and is no longer receiving any updates.
mvent
by BRAHMAI
A Python package that provides an event-driven interface for shared memory communication between processes.
Features
- Shared memory communication between processes
- Event-driven architecture using decorators
- TTL support for temporary data
- Automatic cleanup of expired data
- Thread-safe operations
- In-memory HTTP API: HTTP-like request/response and route handling all in RAM (no network).
- StreamingEvent: Publish/subscribe, chunked/real-time data streams over shared memory.
- SocketsManager: Pub/sub, room/channel-based, socket-like messaging—entirely RAM-backed.
- Monitoring tools: Live stats for pool size, event/message frequency, handler performance.
- Optional encryption: Secure shared memory with symmetric key (requires
cryptography).
Installation
pip install mvent
Quick Start
from mvent import MemoryEventHandler
import time
# Create a memory event handler
memory_events = MemoryEventHandler("my_pool")
# Define an event handler using decorator
@memory_events.on("user_data")
def handle_user_update(new_value):
print(f"User data updated: {new_value}")
# Emit an event
memory_events.emit("user_data", {"name": "John", "age": 30})
# Emit with TTL (expires after 5 seconds)
memory_events.emit("user_data", {"name": "Jane"}, ttl=5.0)
# Keep the program running
time.sleep(6)
memory_events.cleanup()
How It Works
The package uses memory-mapped files for shared memory communication between processes. When a process updates a value in shared memory, all registered event handlers in other processes are automatically notified and executed.
Extended Usage: Advanced APIs
InMemoryHTTPManager
from mvent.core.in_memory_http import InMemoryHTTPManager
http = InMemoryHTTPManager()
@http.route("/echo")
def echo(req): return {"echo": req["data"]}
print(http.send_request("/echo", method="POST", data="hi"))
StreamingEvent
from mvent.core.streaming_event import StreamingEvent
stream = StreamingEvent("my_stream")
stream.subscribe(lambda d: print("Got:", d))
stream.publish("Live Message #1")
SocketsManager
from mvent.core.sockets_manager import SocketsManager
sm = SocketsManager()
room = "test"
sm.connect(room)
sm.subscribe(room, print)
sm.send(room, "socket message!")
MonitoringTools and Encryption
from mvent.core.monitoring import MonitoringTools
from mvent.core.shared_memory import SharedMemoryPool
from cryptography.fernet import Fernet
key = Fernet.generate_key()
secure_pool = SharedMemoryPool("secure_pool", encryption_key=key)
monitor = MonitoringTools(pool=secure_pool)
monitor.record_event("test")
- To enable encryption, install cryptography (
pip install cryptography). - All features are backward compatible.
Advanced Usage
Multiple Handlers
# Multiple handlers for the same event
@memory_events.on("user_data")
def log_user_update(new_value):
print(f"Logging: {new_value}")
@memory_events.on("user_data")
def process_user_update(new_value):
# Process the data
pass
Using TTL
# Data expires after 60 seconds
memory_events.emit("temporary_data", "This will expire", ttl=60.0)
License
MIT License
Metadata
Release files for mvent 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mvent-1.0.3.tar.gz | 3.5 kB | Without provenance | Details for mvent-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mvent-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for mvent-1.0.3-py3-none-any.whl |
Total release size: 7.2 kB
Release files / mvent-1.0.3.tar.gz
| Download URL | mvent-1.0.3.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36a01694704dd220de74e7e4cde4fda8e3de87da83ac8e5fd2fa7c5be8cc1237
|
|
BLAKE2b-256 checksum How to use checksums |
42fd8b99483e7bd15df59e9d695ef04ab8fbf12e2c0d966d2aa6d02bffe1b3d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / mvent-1.0.3-py3-none-any.whl
| Download URL | mvent-1.0.3-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
421132dc341da94cf7d405409ee8995ed48f564b690c6674a5195ad95ebd7e89
|
|
BLAKE2b-256 checksum How to use checksums |
aa5aad622640aeff0dc0b81319c1af0ee23f1f1003b91d241a7b3d242fd91b4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Security for mvent 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.