Skip to main content

Kivy Network 🌐

PyPI version Python versions License: MIT

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 websockets and 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

MIT


Metadata

Release files for kivy-network 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kivy-network 0.1.2
File Size Uploaded Provenance Actions
kivy_network-0.1.2.tar.gz 6.5 kB Without provenance Details for kivy_network-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kivy-network 0.1.2
File Interpreter ABI Platform Actions
kivy_network-0.1.2-py3-none-any.whl Python 3 none any Details for kivy_network-0.1.2-py3-none-any.whl

Total release size: 13.5 kB

Release files / kivy_network-0.1.2.tar.gz

Download URL kivy_network-0.1.2.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3489fcd1afe433687c4d1ec074fd107b8bb97ffdd1588eca279dcd5bd707c1aa
BLAKE2b-256 checksum
How to use checksums
a9cfd0cba1d9b6c9ef6d5f4ceeecf2a8c161c877973d588a8423c24493eb03e5
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / kivy_network-0.1.2-py3-none-any.whl

Download URL kivy_network-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b3b1d5f74c50de2c0d8c47f7e8017417b4aa45d43ac2d2a36968e66e48b6aa8
BLAKE2b-256 checksum
How to use checksums
dbb3330b83009008a64301d9eb389ed90610ca38f5a27a730bce23e170e1df70
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for kivy-network 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page