Python library for gateways, networks, and devices.
Project description
gatenet 🛰️
BETA (0.1.0)
Installation
pip install gatenet
Features
- TCP Server for raw socket data
- UDP Server & Client
- HTTP Server
- Route-based handling
- JSON responses
- POST support
- Minimal, composable, Pythonic design
TCP Server
from gatenet.socket.tcp import TCPServer
server = TCPServer(host='127.0.0.1', port=8000)
@server.on_receive
def handle_data(data, addr):
print(f"[TCP] {addr} sent: {data}")
return f"Echo: {data}"
server.start()
UDP Server & Client
UDP Server
from gatenet.socket.udp import UDPServer
server = UDPServer(host="127.0.0.1", port=9000)
@server.on_receive
def handle_udp(data, addr):
print(f"[UDP] {addr} sent: {data}")
return f"Got your message: {data}"
server.start()
UDP Client
from gatenet.socket.udp import UDPClient
client = UDPClient(host="127.0.0.1", port=9000)
response = client.send("Hello, UDP!")
print(response)
HTTP Server (GET + POST)
from gatenet.http.base import HTTPServerComponent
server = HTTPServerComponent(host="127.0.0.1", port=8080)
@server.route("/status", method="GET")
def status(_req):
return {
"ok": True
}
@server.route("/echo", method="POST")
def echo(_req, data):
return {
"received": data
}
server.start()
Send a POST request
import requests
res = requests.post("http://127.0.0.1:8080/echo", json={"msg": "hi"})
print(res.json()) # {'received': {'msg': 'hi'}}
Tests
pytest
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
gatenet-0.1.0.tar.gz
(5.0 kB
view details)
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 gatenet-0.1.0.tar.gz.
File metadata
- Download URL: gatenet-0.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64b047407adb8b144ea5be26c846b4d31fb680196f451a99496557a8e2932ad4
|
|
| MD5 |
4f4b7cc3b4cb2705a36da3c952c59eec
|
|
| BLAKE2b-256 |
b62f253181a9ed2cb430832a818059ffe35d64c1091b7091d1b1a8411e868e1b
|
File details
Details for the file gatenet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gatenet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0334d2e7c822fc826ccdcf7db26e7a08a9cfae13dd12c3362815bd41e00cd7
|
|
| MD5 |
edcaea01cb27159704cd26f3905a9dc6
|
|
| BLAKE2b-256 |
79364f25abcc7360d0b2de5addcb4f236235c45130fcc228f63f560e80926677
|