kivy-network 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GP-commits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.4
2
+ Name: kivy-network
3
+ Version: 0.1.0
4
+ Summary: A real-time async WebSocket networking engine for Kivy.
5
+ Author-email: Etherum Miners <vjs.sreenivas@gmail.com>
6
+ Project-URL: Homepage, https://github.com/GP-commits/Kivy-Python
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: websockets>=16.0
11
+ Requires-Dist: kivy>=2.3.1
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest==9.0.2; extra == "dev"
14
+ Requires-Dist: pytest-asyncio==1.3.0; extra == "dev"
15
+ Requires-Dist: requests==2.32.5; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # Kivy-Python
19
+ An open-source Python library designed to simplify and accelerate mobile app development with Kivy.
@@ -0,0 +1,2 @@
1
+ # Kivy-Python
2
+ An open-source Python library designed to simplify and accelerate mobile app development with Kivy.
File without changes
@@ -0,0 +1,27 @@
1
+ from kivy.event import EventDispatcher
2
+ from kivy.clock import Clock
3
+
4
+ class NetworkEventDispatcher(EventDispatcher):
5
+ __events__ = ('on_connected', 'on_message', 'on_error')
6
+
7
+ def __init__(self, **kwargs):
8
+ super().__init__(**kwargs)
9
+ self.bind(on_message=self.on_message_handler)
10
+
11
+ def on_connected(self, *args):
12
+ pass
13
+
14
+ def on_message(self, message_data):
15
+ pass
16
+
17
+ def on_error(self, error_msg):
18
+ pass
19
+
20
+ def trigger_message_safely(self, data):
21
+ Clock.schedule_once(lambda dt: self.dispatch('on_message', data), 0)
22
+
23
+ def trigger_connected_safely(self, *args):
24
+ Clock.schedule_once(lambda dt: self.dispatch('on_connected', *args), 0)
25
+
26
+ def trigger_error_safely(self, error_msg):
27
+ Clock.schedule_once(lambda dt: self.dispatch('on_error', error_msg), 0)
@@ -0,0 +1,96 @@
1
+ import asyncio
2
+ import websockets
3
+ import json
4
+ from dataclasses import dataclass
5
+ from typing import Optional, Dict, Any
6
+ from kivy.event import EventDispatcher
7
+ from kivy.clock import Clock
8
+
9
+ @dataclass
10
+ class NetworkMessage:
11
+ type: str
12
+ room: Optional[str]
13
+ content: Optional[str]
14
+ sender_id: Optional[str]
15
+ raw_data: Dict[str, Any]
16
+
17
+ class NetworkEventDispatcher(EventDispatcher):
18
+ __events__ = ('on_connected', 'on_message', 'on_error', 'on_disconnected')
19
+
20
+ def __init__(self, **kwargs):
21
+ super().__init__(**kwargs)
22
+
23
+ def on_connected(self, *args): pass
24
+ def on_message(self, message: NetworkMessage): pass
25
+ def on_error(self, error_msg: str): pass
26
+ def on_disconnected(self, *args): pass
27
+
28
+ def trigger_message_safely(self, message_obj: NetworkMessage):
29
+ Clock.schedule_once(lambda dt: self.dispatch('on_message', message_obj), 0)
30
+
31
+ def trigger_connected_safely(self):
32
+ Clock.schedule_once(lambda dt: self.dispatch('on_connected'), 0)
33
+
34
+ def trigger_error_safely(self, error_msg: str):
35
+ Clock.schedule_once(lambda dt: self.dispatch('on_error', error_msg), 0)
36
+
37
+ def trigger_disconnected_safely(self):
38
+ Clock.schedule_once(lambda dt: self.dispatch('on_disconnected'), 0)
39
+
40
+
41
+ class RealTimeClient(NetworkEventDispatcher):
42
+ def __init__(self, uri: str = "ws://localhost:8765", **kwargs):
43
+ super().__init__(**kwargs)
44
+ self.uri = uri
45
+ self.websocket = None
46
+ self.client_id: Optional[str] = None
47
+ self.connected: bool = False
48
+ self.reconnect_delay: int = 1
49
+ self.max_delay: int = 15
50
+
51
+ async def run_forever(self) -> None:
52
+ while True:
53
+ try:
54
+ print(f"[CLIENT] Attempting to connect to {self.uri}...")
55
+ async with websockets.connect(self.uri) as ws:
56
+ self.websocket = ws
57
+ self.connected = True
58
+ self.reconnect_delay = 1
59
+ self.trigger_connected_safely()
60
+ await self._listen()
61
+
62
+ except (websockets.exceptions.ConnectionClosedError, ConnectionRefusedError):
63
+ self.connected = False
64
+ self.trigger_disconnected_safely()
65
+ self.trigger_error_safely("Connection dropped.")
66
+ await asyncio.sleep(self.reconnect_delay)
67
+ self.reconnect_delay = min(self.reconnect_delay * 2, self.max_delay)
68
+ except Exception as e:
69
+ print(f"[CLIENT] Critical Error: {e}")
70
+ await asyncio.sleep(5)
71
+
72
+ async def _listen(self) -> None:
73
+ async for message in self.websocket:
74
+ data = json.loads(message)
75
+
76
+ if data.get("type") == "welcome":
77
+ self.client_id = data.get("client_id")
78
+ else:
79
+ msg_obj = NetworkMessage(
80
+ type=data.get("type", "unknown"),
81
+ room=data.get("room"),
82
+ content=data.get("content"),
83
+ sender_id=data.get("sender_id"),
84
+ raw_data=data
85
+ )
86
+ self.trigger_message_safely(msg_obj)
87
+
88
+ async def join_room(self, room_name: str) -> None:
89
+ if self.connected and self.websocket:
90
+ data = {"action": "join", "room": room_name}
91
+ await self.websocket.send(json.dumps(data))
92
+
93
+ async def send_chat(self, room_name: str, content: str) -> None:
94
+ if self.connected and self.websocket:
95
+ data = {"action": "message", "room": room_name, "content": content}
96
+ await self.websocket.send(json.dumps(data))
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.4
2
+ Name: kivy-network
3
+ Version: 0.1.0
4
+ Summary: A real-time async WebSocket networking engine for Kivy.
5
+ Author-email: Etherum Miners <vjs.sreenivas@gmail.com>
6
+ Project-URL: Homepage, https://github.com/GP-commits/Kivy-Python
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: websockets>=16.0
11
+ Requires-Dist: kivy>=2.3.1
12
+ Provides-Extra: dev
13
+ Requires-Dist: pytest==9.0.2; extra == "dev"
14
+ Requires-Dist: pytest-asyncio==1.3.0; extra == "dev"
15
+ Requires-Dist: requests==2.32.5; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # Kivy-Python
19
+ An open-source Python library designed to simplify and accelerate mobile app development with Kivy.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ kivy_network/__init__.py
5
+ kivy_network/kivy_bridge.py
6
+ kivy_network/network_client.py
7
+ kivy_network.egg-info/PKG-INFO
8
+ kivy_network.egg-info/SOURCES.txt
9
+ kivy_network.egg-info/dependency_links.txt
10
+ kivy_network.egg-info/requires.txt
11
+ kivy_network.egg-info/top_level.txt
12
+ tests/test_client.py
@@ -0,0 +1,7 @@
1
+ websockets>=16.0
2
+ kivy>=2.3.1
3
+
4
+ [dev]
5
+ pytest==9.0.2
6
+ pytest-asyncio==1.3.0
7
+ requests==2.32.5
@@ -0,0 +1 @@
1
+ kivy_network
@@ -0,0 +1,27 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "kivy-network"
7
+ version = "0.1.0"
8
+ authors = [
9
+ { name="Etherum Miners", email="vjs.sreenivas@gmail.com" },
10
+ ]
11
+ description = "A real-time async WebSocket networking engine for Kivy."
12
+ readme = "README.md"
13
+ requires-python = ">=3.8"
14
+ dependencies = [
15
+ "websockets>=16.0",
16
+ "kivy>=2.3.1"
17
+ ]
18
+
19
+ [project.optional-dependencies]
20
+ dev = [
21
+ "pytest==9.0.2",
22
+ "pytest-asyncio==1.3.0",
23
+ "requests==2.32.5"
24
+ ]
25
+
26
+ [project.urls]
27
+ "Homepage" = "https://github.com/GP-commits/Kivy-Python"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,47 @@
1
+ import asyncio
2
+ import websockets
3
+ import json
4
+ import pytest
5
+
6
+ URI = "ws://localhost:8765"
7
+
8
+ @pytest.mark.asyncio
9
+ async def test_room_join_and_message():
10
+ async with websockets.connect(URI) as ws:
11
+ join_cmd = {"action": "join", "room": "lobby"}
12
+ await ws.send(json.dumps(join_cmd))
13
+
14
+ raw_resp = await ws.recv()
15
+ resp = json.loads(raw_resp)
16
+ assert resp["status"] == "success"
17
+
18
+ msg_cmd = {"action": "message", "room": "lobby", "content": "Hello Team!"}
19
+ await ws.send(json.dumps(msg_cmd))
20
+
21
+ raw_broadcast = await ws.recv()
22
+ broadcast = json.loads(raw_broadcast)
23
+ assert broadcast["room"] == "lobby"
24
+ assert broadcast["content"] == "Hello Team!"
25
+
26
+ @pytest.mark.asyncio
27
+ async def test_stress_multi_room_routing():
28
+ """Stress test: 50 clients in different rooms should only hear their own room's noise."""
29
+
30
+ async def fake_client_task(client_id):
31
+ room_name = "room_A" if client_id % 2 == 0 else "room_B"
32
+
33
+ async with websockets.connect(URI) as ws:
34
+ await ws.send(json.dumps({"action": "join", "room": room_name}))
35
+ await ws.recv()
36
+
37
+ test_content = f"Message from {client_id}"
38
+ await ws.send(json.dumps({"action": "message", "room": room_name, "content": test_content}))
39
+
40
+ raw_data = await ws.recv()
41
+ data = json.loads(raw_data)
42
+
43
+ assert data["room"] == room_name
44
+ assert test_content in data["content"]
45
+
46
+ tasks = [fake_client_task(i) for i in range(50)]
47
+ await asyncio.gather(*tasks)