zapchat 3.0.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.
zapchat-3.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Samarth Chugh (Sam3360)
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.
zapchat-3.0.0/PKG-INFO ADDED
@@ -0,0 +1,103 @@
1
+ Metadata-Version: 2.4
2
+ Name: zapchat
3
+ Version: 3.0.0
4
+ Summary: Terminal-native LAN chat. No accounts, no cloud, no servers - just your local network.
5
+ Author: Samarth Chugh (Sam3360)
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Sam3360/zapchatnpm
8
+ Project-URL: Repository, https://github.com/Sam3360/zapchatnpm
9
+ Project-URL: Issues, https://github.com/Sam3360/zapchatnpm/issues
10
+ Keywords: lan,chat,cli,terminal,p2p,udp,discovery,local-network
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: End Users/Desktop
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Communications :: Chat
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Provides-Extra: dev
21
+ Requires-Dist: build>=1.2; extra == "dev"
22
+ Dynamic: license-file
23
+
24
+ # zapchat (Python)
25
+
26
+ **Terminal-native LAN chat. No accounts, no cloud, no servers — just your
27
+ local network.**
28
+
29
+ This is the Python distribution of [zapchat](https://github.com/Sam3360/zapchatnpm).
30
+ It speaks the same discovery protocol as the Node.js version, so a Python user
31
+ and an npm user on the same Wi-Fi can chat with each other.
32
+
33
+ > The Python client runs the proven protocol v1 wire format (JSON envelopes
34
+ > over TCP, signed discovery beacons). The Node.js client's protocol v2 adds
35
+ > TLS-style encryption on top of the same envelope shapes — the Python client
36
+ > interoperates with npm peers via the shared discovery and messaging format.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ pip install zapchat
42
+ ```
43
+
44
+ ## Run
45
+
46
+ ```bash
47
+ zapchat
48
+ ```
49
+
50
+ That is it. Everyone on the same network who runs `zapchat` shows up
51
+ automatically, and you can start chatting.
52
+
53
+ ```
54
+ zapchat 3.0.0 — LAN chat, no accounts, no server
55
+ you are sam on #general (tcp:45913)
56
+ waiting for people on this network... (ctrl+c to quit, /help)
57
+ * alex connected
58
+ 10:24 alex: morning all
59
+ 10:25 sam: morning! which room are we using today?
60
+ ```
61
+
62
+ ## Commands
63
+
64
+ | Command | What it does |
65
+ | --- | --- |
66
+ | `/help` | Show the command list |
67
+ | `/rooms` | Rooms discovered on the LAN |
68
+ | `/users` `/who` | Who is on the LAN and connected |
69
+ | `/join <room>` | Join a room (created if nobody is in it) |
70
+ | `/name <username>` | Change your display name |
71
+ | `/connect <ip[:port]>` | Connect straight to a peer when discovery is blocked |
72
+ | `/status` | Discovery state, ports, peers |
73
+ | `/quit` | Exit |
74
+
75
+ ## How it works
76
+
77
+ - Every instance sends a small UDP beacon (multicast + subnet broadcast)
78
+ announcing its username, room and TCP port.
79
+ - Beacons are how instances find each other; then they open direct TCP
80
+ connections and exchange newline-delimited JSON messages.
81
+ - Rooms are derived, not stored: a room exists while somebody is in it.
82
+ - There is no server of any kind. If the LAN works, zapchat works.
83
+
84
+ Works with the npm version of zapchat on the same network (same beacons, same
85
+ message protocol).
86
+
87
+ ## Privacy
88
+
89
+ - No accounts, no telemetry, no cloud: the only network traffic is UDP
90
+ beacons and TCP messages on your local network.
91
+ - Config is one small JSON file (your username, a random client id, the last
92
+ room). Chat history stays in memory.
93
+ - Messages are plain text on your LAN — anyone who can capture that traffic
94
+ can read it. For sensitive conversations use an encrypted messenger.
95
+
96
+ ## Requirements
97
+
98
+ - Python 3.9+ (standard library only — zero dependencies)
99
+ - Python 3.9+ on any OS: Windows, macOS, Linux
100
+
101
+ ## License
102
+
103
+ MIT © Samarth Chugh (Sam3360)
@@ -0,0 +1,80 @@
1
+ # zapchat (Python)
2
+
3
+ **Terminal-native LAN chat. No accounts, no cloud, no servers — just your
4
+ local network.**
5
+
6
+ This is the Python distribution of [zapchat](https://github.com/Sam3360/zapchatnpm).
7
+ It speaks the same discovery protocol as the Node.js version, so a Python user
8
+ and an npm user on the same Wi-Fi can chat with each other.
9
+
10
+ > The Python client runs the proven protocol v1 wire format (JSON envelopes
11
+ > over TCP, signed discovery beacons). The Node.js client's protocol v2 adds
12
+ > TLS-style encryption on top of the same envelope shapes — the Python client
13
+ > interoperates with npm peers via the shared discovery and messaging format.
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ pip install zapchat
19
+ ```
20
+
21
+ ## Run
22
+
23
+ ```bash
24
+ zapchat
25
+ ```
26
+
27
+ That is it. Everyone on the same network who runs `zapchat` shows up
28
+ automatically, and you can start chatting.
29
+
30
+ ```
31
+ zapchat 3.0.0 — LAN chat, no accounts, no server
32
+ you are sam on #general (tcp:45913)
33
+ waiting for people on this network... (ctrl+c to quit, /help)
34
+ * alex connected
35
+ 10:24 alex: morning all
36
+ 10:25 sam: morning! which room are we using today?
37
+ ```
38
+
39
+ ## Commands
40
+
41
+ | Command | What it does |
42
+ | --- | --- |
43
+ | `/help` | Show the command list |
44
+ | `/rooms` | Rooms discovered on the LAN |
45
+ | `/users` `/who` | Who is on the LAN and connected |
46
+ | `/join <room>` | Join a room (created if nobody is in it) |
47
+ | `/name <username>` | Change your display name |
48
+ | `/connect <ip[:port]>` | Connect straight to a peer when discovery is blocked |
49
+ | `/status` | Discovery state, ports, peers |
50
+ | `/quit` | Exit |
51
+
52
+ ## How it works
53
+
54
+ - Every instance sends a small UDP beacon (multicast + subnet broadcast)
55
+ announcing its username, room and TCP port.
56
+ - Beacons are how instances find each other; then they open direct TCP
57
+ connections and exchange newline-delimited JSON messages.
58
+ - Rooms are derived, not stored: a room exists while somebody is in it.
59
+ - There is no server of any kind. If the LAN works, zapchat works.
60
+
61
+ Works with the npm version of zapchat on the same network (same beacons, same
62
+ message protocol).
63
+
64
+ ## Privacy
65
+
66
+ - No accounts, no telemetry, no cloud: the only network traffic is UDP
67
+ beacons and TCP messages on your local network.
68
+ - Config is one small JSON file (your username, a random client id, the last
69
+ room). Chat history stays in memory.
70
+ - Messages are plain text on your LAN — anyone who can capture that traffic
71
+ can read it. For sensitive conversations use an encrypted messenger.
72
+
73
+ ## Requirements
74
+
75
+ - Python 3.9+ (standard library only — zero dependencies)
76
+ - Python 3.9+ on any OS: Windows, macOS, Linux
77
+
78
+ ## License
79
+
80
+ MIT © Samarth Chugh (Sam3360)
@@ -0,0 +1,37 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "zapchat"
7
+ version = "3.0.0"
8
+ description = "Terminal-native LAN chat. No accounts, no cloud, no servers - just your local network."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Samarth Chugh (Sam3360)" }]
14
+ keywords = ["lan", "chat", "cli", "terminal", "p2p", "udp", "discovery", "local-network"]
15
+ classifiers = [
16
+ "Environment :: Console",
17
+ "Intended Audience :: End Users/Desktop",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Topic :: Communications :: Chat",
22
+ ]
23
+ dependencies = []
24
+
25
+ [project.optional-dependencies]
26
+ dev = ["build>=1.2"]
27
+
28
+ [project.scripts]
29
+ zapchat = "zapchat.cli:main"
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/Sam3360/zapchatnpm"
33
+ Repository = "https://github.com/Sam3360/zapchatnpm"
34
+ Issues = "https://github.com/Sam3360/zapchatnpm/issues"
35
+
36
+ [tool.setuptools]
37
+ packages = ["zapchat"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,81 @@
1
+ """Tests for the wire protocol helpers."""
2
+
3
+ import sys
4
+ import os
5
+
6
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
7
+
8
+ from zapchat.protocol import (
9
+ create_envelope,
10
+ decode_frames,
11
+ encode_envelope,
12
+ parse_announce_data,
13
+ parse_envelope,
14
+ parse_message_data,
15
+ sanitize_room_name,
16
+ sanitize_username,
17
+ )
18
+
19
+
20
+ def test_roundtrip_envelope():
21
+ sender = {"clientId": "zc-test-1234", "username": "sam"}
22
+ envelope = create_envelope("MESSAGE", sender["clientId"], sender["username"], room="general", data={"text": "hi"})
23
+ wire = encode_envelope(envelope)
24
+ parsed, leftover = decode_frames(wire)
25
+ assert leftover == ""
26
+ assert len(parsed) == 1
27
+ assert parsed[0]["type"] == "MESSAGE"
28
+ assert parsed[0]["data"]["text"] == "hi"
29
+
30
+
31
+ def test_rejects_garbage():
32
+ for bad in ["hello", None, [], 42]:
33
+ assert parse_envelope(bad) is None
34
+
35
+
36
+ def test_rejects_wrong_version_and_types():
37
+ envelope = create_envelope("PING", "zc-test-1234", "sam")
38
+ assert parse_envelope({**envelope, "v": 99}) is None
39
+ assert parse_envelope({**envelope, "type": "DROP TABLE"}) is None
40
+ assert parse_envelope({**envelope, "from": "x"}) is None
41
+
42
+
43
+ def test_strips_control_characters():
44
+ # ANSI styling is stripped and the remaining name is clean text —
45
+ # matching the npm client's repair-don't-reject behaviour.
46
+ assert sanitize_username("\x1b[31mhacker\x1b[0m\x07") == "hacker"
47
+ text = parse_message_data({"text": "hi\x1b[31mthere"})
48
+ assert text == "hithere"
49
+ # Pure control garbage with no usable name is rejected.
50
+ assert sanitize_username("\x07\x1b") is None
51
+
52
+
53
+ def test_room_names_are_normalised():
54
+ assert sanitize_room_name("General") == "general"
55
+ assert sanitize_room_name("bad/room") is None
56
+ assert sanitize_room_name("") is None
57
+
58
+
59
+ def test_announce_parsing():
60
+ data = parse_announce_data({"port": 45913, "addresses": ["192.168.1.5", "nope"], "rooms": ["general", "BAD/", 42]})
61
+ assert data["port"] == 45913
62
+ assert data["addresses"] == ["192.168.1.5"]
63
+ assert data["rooms"] == ["general"]
64
+
65
+
66
+ def test_frames_split_across_chunks():
67
+ first = encode_envelope(create_envelope("PING", "zc-test-1234", "sam"))
68
+ second = encode_envelope(create_envelope("PONG", "zc-test-1234", "sam"))
69
+ stream = first + second[:5]
70
+ parsed, buffer = decode_frames(stream)
71
+ assert len(parsed) == 1
72
+ parsed2, buffer2 = decode_frames(second[5:].encode() if isinstance(second[5:], str) else second[5:], buffer)
73
+ assert len(parsed2) == 1
74
+
75
+
76
+ def test_max_message_length():
77
+ long_text = "x" * 1500
78
+ result = parse_message_data({"text": long_text})
79
+ assert result is not None
80
+ assert len(result) <= 1000
81
+ assert parse_message_data({"text": "x" * 5000}) is None
@@ -0,0 +1,120 @@
1
+ """Live integration test: two real zapchat processes chat over the LAN.
2
+
3
+ Spawns two CLI processes with separate config dirs, waits for them to
4
+ discover each other over UDP, then sends a message from each side and checks
5
+ both arrive. Mirrors the npm project's cli end-to-end test.
6
+ """
7
+
8
+ import os
9
+ import subprocess
10
+ import threading
11
+ import sys
12
+ import tempfile
13
+ import time
14
+
15
+
16
+ def _find_exe():
17
+ """The installed CLI: env override, then common venv spots, then PATH."""
18
+ override = os.environ.get("ZAPCHAT_EXE")
19
+ if override:
20
+ return override
21
+ candidates = [
22
+ os.path.join(sys.prefix, "Scripts", "zapchat.exe"),
23
+ os.path.join(sys.prefix, "bin", "zapchat"),
24
+ ]
25
+ for candidate in candidates:
26
+ if os.path.exists(candidate):
27
+ return candidate
28
+ return "zapchat"
29
+
30
+
31
+ EXE = _find_exe()
32
+
33
+
34
+ class Instance:
35
+ """One spawned zapchat process with a single reader thread.
36
+
37
+ Exactly one thread consumes the process's stdout into a shared list —
38
+ a second iterating reader would steal lines and starve later assertions.
39
+ """
40
+
41
+ def __init__(self, name, room, config_dir):
42
+ self.name = name
43
+ self.process = subprocess.Popen(
44
+ [EXE, "--name", name, "--room", room],
45
+ stdin=subprocess.PIPE,
46
+ stdout=subprocess.PIPE,
47
+ stderr=subprocess.STDOUT,
48
+ text=True,
49
+ bufsize=1,
50
+ env={**os.environ, "ZAPCHAT_CONFIG_DIR": config_dir, "PYTHONUNBUFFERED": "1"},
51
+ )
52
+ self.lines = []
53
+ threading.Thread(target=self._reader, daemon=True).start()
54
+
55
+ def _reader(self):
56
+ for line in self.process.stdout:
57
+ self.lines.append(line)
58
+
59
+ def output(self):
60
+ return "".join(self.lines)
61
+
62
+ def wait_for(self, needle, timeout=20.0):
63
+ deadline = time.time() + timeout
64
+ while time.time() < deadline:
65
+ if needle in self.output():
66
+ return True
67
+ time.sleep(0.2)
68
+ return False
69
+
70
+ def send(self, text):
71
+ self.process.stdin.write(text + "\n")
72
+ self.process.stdin.flush()
73
+
74
+ def stop(self):
75
+ try:
76
+ self.process.stdin.close()
77
+ except OSError:
78
+ pass
79
+ self.process.terminate()
80
+
81
+
82
+ def test_two_instances_chat():
83
+ # The live test needs a runnable CLI. When ZAPCHAT_EXE is unset and the
84
+ # resolved default is not our own Python CLI (e.g. the npm shim on PATH),
85
+ # skip rather than test the wrong binary.
86
+ import shutil
87
+
88
+ resolved = os.environ.get("ZAPCHAT_EXE") or shutil.which("zapchat")
89
+ if resolved is None or resolved.lower().endswith(".cmd"):
90
+ import pytest
91
+
92
+ pytest.skip("no Python zapchat CLI on PATH; set ZAPCHAT_EXE to run the live test")
93
+
94
+ with tempfile.TemporaryDirectory() as tmp:
95
+ alice = Instance("alice", "general", os.path.join(tmp, "a"))
96
+ bob = Instance("bob", "general", os.path.join(tmp, "b"))
97
+
98
+ try:
99
+ # Discovery: each side should connect to the other within seconds.
100
+ assert alice.wait_for("connected", timeout=30), f"alice never saw bob: {alice.output()!r}"
101
+ assert bob.wait_for("connected", timeout=10), f"bob never saw alice: {bob.output()!r}"
102
+
103
+ # Messages in both directions.
104
+ alice.send("hello from alice")
105
+ assert bob.wait_for("hello from alice", timeout=10), f"bob output: {bob.output()!r}"
106
+
107
+ bob.send("hi alice, this is bob")
108
+ assert alice.wait_for("hi alice, this is bob", timeout=10), f"alice output: {alice.output()!r}"
109
+
110
+ # A /command runs locally without being sent as chat.
111
+ alice.send("/rooms")
112
+ assert alice.wait_for("general", timeout=5), f"alice output: {alice.output()!r}"
113
+ finally:
114
+ alice.stop()
115
+ bob.stop()
116
+
117
+
118
+ if __name__ == "__main__":
119
+ test_two_instances_chat()
120
+ print("TWO-INSTANCE CHAT OK")
@@ -0,0 +1,3 @@
1
+ """zapchat: terminal-native LAN chat with no accounts and no server."""
2
+
3
+ __version__ = "3.0.0"