Skip to main content

Python client for the MIP (MSIP) protocol - handles connections, events, errors, and auto-reconnection

Project description

MIP-Client-python

PyPI version License: MIT

Python async client for the MIP (MSIP) protocol - handles connections, events, errors, and auto-reconnection.

Server implementation: MIP Server

Part of the MIP Client family:

Installation

pip install mip-client-python

Usage

Basic Connection

import asyncio
from mip_client import MIPClient

async def main():
    client = MIPClient(host="127.0.0.1", port=9000, client_id="my_client_123")

    # Register event callbacks
    client.on_connect(lambda: print("Connected to server"))
    client.on_disconnect(lambda: print("Disconnected"))
    client.on_error(lambda err: print(f"Error: {err.message}"))
    client.on_message(lambda msg: print(f"[{msg.topic}] {msg.message}"))

    # Connect
    await client.connect()

    # Keep running
    await asyncio.sleep(60)
    await client.disconnect()

asyncio.run(main())

Subscribe / Publish

# Subscribe to a topic
client.subscribe("my-topic")

# Listen for messages
def handle_message(msg):
    print(f"Topic: {msg.topic}")
    print(f"Message: {msg.message}")

client.on_message(handle_message)

# Publish a message
client.publish("my-topic", "Hello World!")

Advanced Options

from mip_client import MIPClient, Flags

client = MIPClient(
    host="127.0.0.1",
    port=9000,
    client_id="my_client_123",  # Optional client identifier
    auto_reconnect=True,        # Auto-reconnect (default: True)
    reconnect_delay=3.0,        # Delay between reconnections in seconds (default: 3.0)
    max_reconnect_attempts=10,  # Max attempts (0 = infinite)
    ping_interval=5.0,          # Ping interval in seconds (0 = disabled)
)

# Publish with flags
client.publish("urgent-topic", "Important!", Flags.URGENT | Flags.ACK_REQUIRED)

# Listen for ACKs
client.on_ack(lambda msg_id: print(f"ACK received for: {msg_id}"))

# Manual ping
client.ping()
client.on_pong(lambda: print("Pong received!"))

Auto-Reconnection

client.on_reconnecting(lambda attempt: print(f"Reconnection attempt #{attempt}..."))

def on_connect():
    # Re-subscribe after reconnection
    client.subscribe("my-topic")

client.on_connect(on_connect)

Using create_client helper

from mip_client import create_client

client = create_client("127.0.0.1", 9000, auto_reconnect=True)

API Reference

MIPClient

  • connect() - Connect to the server (async)
  • disconnect() - Disconnect from the server (async)
  • subscribe(topic, require_ack=True) - Subscribe to a topic
  • unsubscribe(topic, require_ack=True) - Unsubscribe from a topic
  • publish(topic, message, flags=Flags.NONE) - Publish a message
  • ping() - Send a ping to the server

Events

  • on_connect(callback) - Called when connected
  • on_disconnect(callback) - Called when disconnected
  • on_reconnecting(callback) - Called when reconnecting (receives attempt number)
  • on_message(callback) - Called when a message is received
  • on_event(callback) - Called when an event is received
  • on_ack(callback) - Called when an ACK is received
  • on_pong(callback) - Called when a pong is received
  • on_error(callback) - Called when an error occurs

Flags

  • Flags.NONE - No flags
  • Flags.ACK_REQUIRED - Request acknowledgment
  • Flags.COMPRESSED - Compressed payload
  • Flags.URGENT - Urgent message

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

mip_client_python-1.0.2.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

mip_client_python-1.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mip_client_python-1.0.2.tar.gz.

File metadata

  • Download URL: mip_client_python-1.0.2.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mip_client_python-1.0.2.tar.gz
Algorithm Hash digest
SHA256 15efc1d4717dbcd6a53368a57ea5f13d815c8caf7b4b2f40ab084f82b9f08ef8
MD5 ad6a2208a428dd51097201c77bfe0998
BLAKE2b-256 bdefeed293bf09358be263941113b30baaeb5baec394b534bcf825e62003fd7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mip_client_python-1.0.2.tar.gz:

Publisher: pypi.yml on DoctorPok42/MIP-Clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mip_client_python-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for mip_client_python-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0fb2832e067c509d4ce5fa599ad23ea1b87101fb1c86be500b09676e89692859
MD5 afd2e0a821d8f464bf11827c762901a5
BLAKE2b-256 7ab2bef45057183ca18fbdf4346c00aacfa55f891966e4df0d139ac14b58d78b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mip_client_python-1.0.2-py3-none-any.whl:

Publisher: pypi.yml on DoctorPok42/MIP-Clients

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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