Skip to main content

Python library for gateways, networks, and devices.

Project description

gatenet 🛰️

BETA

Changelog

Static Badge

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.5.0.tar.gz (12.7 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.5.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gatenet-0.5.0.tar.gz
Algorithm Hash digest
SHA256 29d4566da169c2ea09247cca568a8db044fee871156ad6c29ea06450e1fed8f7
MD5 08256daaf17f541475ca284508339c7c
BLAKE2b-256 bc782e41aa087a805fb5ae6cfb29b5db9213ec1892b9f61c155b4377602d73de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gatenet-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fdaa121a56f625651579d9ffb28a6f43fe03eb067f80a011b2d964e2eb187a2
MD5 64f8dca6b9e9628ea1f881e72a04bf54
BLAKE2b-256 cb252cbd7182db3983aca970d0791579bd60b471d0d4ca13365f35dddef63cff

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