Skip to main content

Python library for gateways, networks, and devices.

Project description

gatenet 🛰️

BETA

Changelog

Package PyPI
Python Python
Tests CI codecov
License 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


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.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gatenet-0.3.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file gatenet-0.3.0.tar.gz.

File metadata

  • Download URL: gatenet-0.3.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for gatenet-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c9fe1012a3832e82502d82ae403f33de7cd1be0f201437711000ff9d600667fe
MD5 a509486e6089f0559bcb28f056c6d382
BLAKE2b-256 50dd0c214cf5ec9088f4b9e0a7a855ed50582fbf4374fee4d77cd9a463edc0ca

See more details on using hashes here.

File details

Details for the file gatenet-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: gatenet-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for gatenet-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ebec69f11cb304c4e8c1ad0a83dbf9592f53320ceb99a59b94388c459ee616d1
MD5 7a7f49b78300cff67b04957039314d59
BLAKE2b-256 4c6ca8c3cd899c6a6e40e6a9dfb8ea8e932c9e49db33f1902093ab70f9edc472

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page