A real-time async WebSocket networking engine for Kivy.
Project description
Kivy Network 🌐
A robust, asynchronous, real-time WebSocket networking engine specifically designed for Kivy applications.
Building real-time multiplayer games, chat applications, or live dashboards in Kivy can be tricky because blocking network calls freeze the Kivy UI thread. kivy-network solves this by bridging the gap between Python's asyncio WebSockets and Kivy's 60FPS Clock, ensuring your app stays perfectly smooth.
Features
- Thread-Safe UI Updates: Safely routes background network events into Kivys main thread using
Clock.schedule_once. - Indestructible Client: Built-in auto-reconnect engine with backoff. Survives network drops, tunnels, and server reboots automatically.
- Pro-Level Typing: Uses strict Python
dataclasses(NetworkMessage) for full IDE autocomplete support. Say goodbye to dictionary typo bugs. - Ghost Hunter: Built-in Ping/Pong heartbeat system safely cleans up dead or half-open connections.
- Lightweight: Minimal dependencies. Built purely on standard
websocketsand Kivy.
Installation
Install via pip or uv:
pip install kivy-network
(Note: Ensure you have Kivy installed and configured for your operating system).
Quick Start
1. The Kivy Client
Here is how easy it is to drop kivy-network into your application.
import asyncio
from kivy.app import App
from kivy.uix.label import Label
from kivy-network.network_client import RealTimeClient
class MultiplayerApp(App):
def build(self):
self.label = Label(text="Connecting...")
self.network = RealTimeClient("ws://localhost:8765")
self.network.bind(on_connected=self.on_connect)
self.network.bind(on_message=self.on_message)
self.network.bind(on_disconnected=self.on_disconnect)
asyncio.create_task(self.network.run_forever())
return self.label
def on_connect(self, instance):
self.label.text = "Connected! Joining room..."
asyncio.create_task(self.network.join_room("lobby"))
def on_message(self, instance, message):
if message.type == "message":
self.label.text = f"User {message.sender_id} says: {message.content}"
def on_disconnect(self, instance):
self.label.text = "Connection lost. Reconnecting..."
if __name__ == "__main__":
asyncio.run(MultiplayerApp().async_run(async_lib='asyncio'))
2. The NetworkMessage API
Every time your UI receives an on_message event, it receives a strictly-typed NetworkMessage dataclass with the following properties available for autocomplete:
message.type(str) - E.g., 'welcome', 'message', 'admin'message.room(str | None)message.content(str | None)message.sender_id(str | None)message.raw_data(dict) - The raw JSON payload fallback.
Running a Test Server
kivy-network connects seamlessly to any standard WebSocket server.
We recommend spinning up a quick python server using the websockets library:
import asyncio
import websockets
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
async def main():
async with websockets.serve(echo, "localhost", 8765):
await asyncio.Future()
asyncio.run(main())
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
License
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 kivy_network-0.1.2.tar.gz.
File metadata
- Download URL: kivy_network-0.1.2.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3489fcd1afe433687c4d1ec074fd107b8bb97ffdd1588eca279dcd5bd707c1aa
|
|
| MD5 |
25fa56cec5a069fc8712683365446e21
|
|
| BLAKE2b-256 |
a9cfd0cba1d9b6c9ef6d5f4ceeecf2a8c161c877973d588a8423c24493eb03e5
|
File details
Details for the file kivy_network-0.1.2-py3-none-any.whl.
File metadata
- Download URL: kivy_network-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b3b1d5f74c50de2c0d8c47f7e8017417b4aa45d43ac2d2a36968e66e48b6aa8
|
|
| MD5 |
52da8d0ce226e73607ef04be020f776a
|
|
| BLAKE2b-256 |
dbb3330b83009008a64301d9eb389ed90610ca38f5a27a730bce23e170e1df70
|