Skip to main content

A shared memory event system for Python

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

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

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

mvent-1.0.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mvent-1.0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file mvent-1.0.1.tar.gz.

File metadata

  • Download URL: mvent-1.0.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for mvent-1.0.1.tar.gz
Algorithm Hash digest
SHA256 10e48eec95e28cb26b0a85d936bd4f61e52272b87088679f4d5590dbffa3c4fc
MD5 5a6d89f35f926806c9872cafa208afb0
BLAKE2b-256 c3c81d68382a4546bf51c01fc5bb1d669bf0aaaf84b53c453a0a005a990e048e

See more details on using hashes here.

File details

Details for the file mvent-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mvent-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for mvent-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08f6e1027c26d7ea919acf36fa9c5785b5a9d0425ac5b5a00d7f725254b86e8d
MD5 10c6125d6af1ce441e17ed7a5422bba4
BLAKE2b-256 e1d20c70f9ec771d884f767588a84bf10714a9fd1bc8789f5c97e464dc536467

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page