Skip to main content

Python bindings for tokio-memq

Project description

tokio-memq-python

PyPI version Build Status License: MIT Python Version

High-performance, asynchronous, in-memory message queue bindings for Python, powered by Rust's tokio and tokio-memq.

Features

  • High Performance: Built on Rust's Tokio runtime for ultra-low latency and high throughput.
  • Async/Await Support: Fully integrated with Python's asyncio.
  • Partition Support: Built-in support for partitioned topics (RoundRobin, Hash, Random, Fixed routing).
  • Type Safety: Leverages Rust's safety guarantees under the hood.
  • Cross-Platform: Pre-compiled wheels for Linux, Windows, and macOS (Intel & Apple Silicon).

Installation

pip install tokio-memq-python

Requires Python 3.8 or later.

Usage

Basic Usage

Simple publish-subscribe pattern using default topic settings.

import asyncio
from tokio_memq import MessageQueue

async def main():
    # Initialize the Message Queue
    mq = MessageQueue()
    
    # Create a publisher for "test_topic"
    publisher = mq.publisher("test_topic")
    
    # Create a subscriber
    subscriber = await mq.subscriber("test_topic")
    
    # Publish a message (can be any JSON-serializable object)
    await publisher.publish({"id": 1, "content": "Hello World"})
    
    # Receive the message
    msg = await subscriber.recv()
    print(f"Received: {msg}")

if __name__ == "__main__":
    asyncio.run(main())

Partitioned Topics

Scale your application by distributing messages across multiple partitions.

import asyncio
from tokio_memq import MessageQueue

async def main():
    mq = MessageQueue()
    topic = "user_events"
    
    # 1. Create a topic with 4 partitions
    #    This allows parallel consumption by up to 4 consumers
    await mq.create_partitioned_topic(topic, partition_count=4)
    
    # 2. Configure Hash routing
    #    "Hash" strategy ensures messages with the same key go to the same partition.
    #    key="message" tells the router to use the key provided in publish().
    await mq.set_partition_routing(topic, "Hash", key="message")
    
    # 3. Publish messages with keys
    pub = mq.publisher(topic)
    
    # User A's events will always go to the same partition (e.g., Partition 1)
    await pub.publish({"event": "login"}, key="user_A")
    await pub.publish({"event": "click"}, key="user_A")
    
    # User B's events will go to a different partition (e.g., Partition 3)
    await pub.publish({"event": "login"}, key="user_B")
    
    # 4. Subscribe to a specific partition
    #    In a real app, you would distribute these partition IDs across different workers
    sub_p1 = await mq.subscribe_partition(topic, 1) # Listening for User A
    
    msg = await sub_p1.recv()
    print(f"Worker for Partition 1 received: {msg}")

if __name__ == "__main__":
    asyncio.run(main())

API Reference

MessageQueue

The main entry point for interacting with the queue.

  • publisher(topic: str) -> Publisher: Get a publisher instance for a topic.
  • subscriber(topic: str) -> Subscriber: Subscribe to a standard topic.
  • create_partitioned_topic(topic: str, partition_count: int, options: TopicOptions = None): Create a topic with multiple partitions.
  • set_partition_routing(topic: str, strategy: str, key: str = None, fixed_id: int = None): Configure routing strategy.
    • strategy: "RoundRobin", "Random", "Hash", "Fixed".
  • subscribe_partition(topic: str, partition_id: int) -> Subscriber: Subscribe to a specific partition.
  • list_partitioned_topics() -> List[str]: Get all partitioned topics.
  • delete_partitioned_topic(topic: str): Remove a topic and its partitions.

Publisher

  • publish(data: Any, key: str = None): Asynchronously publish data.
    • data: Any Python object serializable to JSON (dict, list, str, int, etc.).
    • key: Optional string key, required only for "Hash" routing on partitioned topics.

Subscriber

  • recv() -> Any: Asynchronously wait for and return the next message.

TopicOptions

Configuration object for topic creation.

from tokio_memq import TopicOptions

opts = TopicOptions()
opts.max_messages = 1000      # Max queue depth per partition
opts.message_ttl_ms = 60000   # Message time-to-live in ms
opts.lru_enabled = True       # Evict oldest when full

License

This project is licensed under the 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

tokio_memq_python-0.1.2.tar.gz (17.0 kB view details)

Uploaded Source

Built Distributions

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

tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (1.5 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ i686

tokio_memq_python-0.1.2-cp38-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.5 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ i686

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARMv7l

tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

tokio_memq_python-0.1.2-cp38-abi3-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

tokio_memq_python-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file tokio_memq_python-0.1.2.tar.gz.

File metadata

  • Download URL: tokio_memq_python-0.1.2.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for tokio_memq_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 44a2912f0629dad7d9a37c6d33ff0612a64ca2e06bd6e12c74da23fd0dd26244
MD5 e73f4d72303f4697b8be9a8cb3cdb232
BLAKE2b-256 baa6d8f23e4245f3f7afb31c8be000bc95e37a4c4fc3879ce47b0682713723e6

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 347e740c68db40855c75a9c16d2b849ddedea0d1c928f289e96671330a3800e3
MD5 a14bb70d81241ee884ef97b977aaf87a
BLAKE2b-256 d7969538b908980a3ff57959c88f51405943ba61006a635a0a6ac8c4c864878f

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-pp311-pypy311_pp73-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 0e29577a0757e5a8b0f62be9a8f1e8781e49ca09c2681290798b12152b0668ea
MD5 fbf7f1e1514df6d02b2c85e6347c13f7
BLAKE2b-256 8363a17ce7b15de09696772e2ccf61c46400bfec85abebfb3d723848b88b17e6

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 747ba4006cc7da084f53c15e1334b5933cdaa608b5382c471bcbfcb3abdd13e1
MD5 d4dc11647a57153209ce441d04ecb15f
BLAKE2b-256 613834d307d961bdd2c7b1e380dc866c7f114b066e498771058d17c9a501010f

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8a4f02e14d489faf49977ea3ee8a81bcbfeeaa0a5e392f7184faf1e1246a4f88
MD5 2e6fb9d7dc088527d78b48e12bd0d8b8
BLAKE2b-256 95265f11e92e5dcc4c54a92d119f012d97198aad17af8d0a8fa6b1bcb1acd4af

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a0b0816c3385e4af0cb2a2bebcffc4ca57aa8bbe0de3b78191dbe626a110581d
MD5 bdfc5c3f217dd0396e4f75353f7b897f
BLAKE2b-256 8bb6f08c94007ad385bea9936aa3241702f9b87aeaaee8eb0653284b30e1afea

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 c9e0ccb095a2a6a574161e30a51a4b49a30f9af40b0931c2c4e0b95ea968c086
MD5 eae730474a026cf5b961de7e836730d6
BLAKE2b-256 9e0b3ee248e3d29e1117f03291b4d37cb49b23b70a4582b7532a86602e64662f

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 13376ee0aec6bfb131d4682df3c7b1ab21d730e9e2b5b064fb0ca84b6d1ee686
MD5 3f54a0eb9caf146f8f767b11a9ed3c7e
BLAKE2b-256 fd2d89d1cfbcd493273902735f3ea663b1094cf30d7b229313aec7cac5afef57

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1b30f12e616c32cc20c10cdf578ec3125d7d22fa546999f1d45462425cf5b8a6
MD5 e8b1e1d12123230de5935003fe057f6b
BLAKE2b-256 dfecabf47e3be17d92cdf180ebbcdd389ddf69228046ae8791a73597168ca02f

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 602d7198ac4ce6d970d09e6cf9d8d0bb840687f585e32eb413793bc0a7caf4b3
MD5 ffc4ad510e7a46da6e687637741d2c94
BLAKE2b-256 25f6a0d8a87a69821233fbfbad1ff78559196459a3e765d63cea97e5320941e3

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0560d67fd39a46fa7eeabb7b82230bbfb8baf28ccd33ab926a4ac2c72fa92f1
MD5 7cc47b6a2f6df03b3d7d7c5087017e6d
BLAKE2b-256 f20e20261fc34a014e7a35bbeff060664f4cd8f5fd3afdd46f843710d159268d

See more details on using hashes here.

File details

Details for the file tokio_memq_python-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tokio_memq_python-0.1.2-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5c6193c6f080c5749bb0af0eaae093786c7cbf05956ce186fb6ee8378b839cb6
MD5 445d72484bbf56e068e1c0b2412c3be8
BLAKE2b-256 224fc65f78a2f7aac884504dc7ed7fbab04cc153aa89a87bbab6935082a5aa4f

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