Python library for gateways, networks, and devices.
Project description
gatenet 🛰️
BETA
| Package | |
| Python | |
| Tests | |
| License |
Python networking toolkit for sockets, UDP, and HTTP microservices — modular and testable.
Installation
pip install gatenet
Features
- TCP for raw socket data
- UDP
- HTTP
- Route-based handling
- JSON responses
- Dynamic request handling
- Custom headers
- Error handling
- Timeout handling
- 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 & Client
HTTP Server
from gatenet.http.server 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()
HTTP Client
All requests return a dictionary with the following structure:
{
"ok": bool, # True if the request was successful
"status": int, # HTTP status code
"data": dict, # Parsed JSON response data
"error": str # Error message if the request failed
}
from gatenet.http.client import HTTPClient
client = HTTPClient("http://127.0.0.1:8080")
res = client.get("/status")
if res["ok"]:
print("Success:", res["data"])
else:
print("Error:", res["error"])
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.3.2.tar.gz
(7.1 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.3.2.tar.gz.
File metadata
- Download URL: gatenet-0.3.2.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7fd160dd983c49046b39d32599c35be9c03cc16b131e983a30a50483e192810
|
|
| MD5 |
1f2e9a3088e1f3521538451ef9383d5e
|
|
| BLAKE2b-256 |
ab299cb2d0ff47b1fb8dd8392c2efcd75603116d6b789f5ec660ab21db560cac
|
File details
Details for the file gatenet-0.3.2-py3-none-any.whl.
File metadata
- Download URL: gatenet-0.3.2-py3-none-any.whl
- Upload date:
- Size: 5.7 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 |
258b235839f77a0d01cba24a7813d186905e1a466f366604b340fb25c987c056
|
|
| MD5 |
26b9e6721be4357e3591face28933ccf
|
|
| BLAKE2b-256 |
1b197fdf0144214bab4cb34eb8544dc39b4bb281ed8e60b504a95b46c8560fc8
|