Python client for the MIP (MSIP) protocol - handles connections, events, errors, and auto-reconnection
Project description
MIP-Client-python
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:
- TypeScript: @mip-client/ts
- Python: mip-client-python (this package)
- Rust: mip-client
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 topicunsubscribe(topic, require_ack=True)- Unsubscribe from a topicpublish(topic, message, flags=Flags.NONE)- Publish a messageping()- Send a ping to the server
Events
on_connect(callback)- Called when connectedon_disconnect(callback)- Called when disconnectedon_reconnecting(callback)- Called when reconnecting (receives attempt number)on_message(callback)- Called when a message is receivedon_event(callback)- Called when an event is receivedon_ack(callback)- Called when an ACK is receivedon_pong(callback)- Called when a pong is receivedon_error(callback)- Called when an error occurs
Flags
Flags.NONE- No flagsFlags.ACK_REQUIRED- Request acknowledgmentFlags.COMPRESSED- Compressed payloadFlags.URGENT- Urgent message
Project details
Release history Release notifications | RSS feed
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15efc1d4717dbcd6a53368a57ea5f13d815c8caf7b4b2f40ab084f82b9f08ef8
|
|
| MD5 |
ad6a2208a428dd51097201c77bfe0998
|
|
| BLAKE2b-256 |
bdefeed293bf09358be263941113b30baaeb5baec394b534bcf825e62003fd7a
|
Provenance
The following attestation bundles were made for mip_client_python-1.0.2.tar.gz:
Publisher:
pypi.yml on DoctorPok42/MIP-Clients
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mip_client_python-1.0.2.tar.gz -
Subject digest:
15efc1d4717dbcd6a53368a57ea5f13d815c8caf7b4b2f40ab084f82b9f08ef8 - Sigstore transparency entry: 1074357304
- Sigstore integration time:
-
Permalink:
DoctorPok42/MIP-Clients@e5d77938a3454e9bdfc06af0c380882ebb48bfd3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DoctorPok42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@e5d77938a3454e9bdfc06af0c380882ebb48bfd3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mip_client_python-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mip_client_python-1.0.2-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fb2832e067c509d4ce5fa599ad23ea1b87101fb1c86be500b09676e89692859
|
|
| MD5 |
afd2e0a821d8f464bf11827c762901a5
|
|
| BLAKE2b-256 |
7ab2bef45057183ca18fbdf4346c00aacfa55f891966e4df0d139ac14b58d78b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mip_client_python-1.0.2-py3-none-any.whl -
Subject digest:
0fb2832e067c509d4ce5fa599ad23ea1b87101fb1c86be500b09676e89692859 - Sigstore transparency entry: 1074357307
- Sigstore integration time:
-
Permalink:
DoctorPok42/MIP-Clients@e5d77938a3454e9bdfc06af0c380882ebb48bfd3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/DoctorPok42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@e5d77938a3454e9bdfc06af0c380882ebb48bfd3 -
Trigger Event:
push
-
Statement type: