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.4.0.tar.gz (11.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.4.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gatenet-0.4.0.tar.gz
  • Upload date:
  • Size: 11.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.4.0.tar.gz
Algorithm Hash digest
SHA256 70c956e6f8b431859fcf4290ec4082c0dde4fca8cd904534baab498a9cf0c18d
MD5 26d10ce866ed09a47f1d3c2865f1c1fb
BLAKE2b-256 f291aa67805afdc12bae2cf1c6d85cef3a04032b9155ab41b5d1635fa56b5731

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gatenet-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff39b6ca2cf40215738cc3fc33c937593874040fd04e6aec678e8d9cdad049f2
MD5 63c0b66bb91f73ca00607263ce72b087
BLAKE2b-256 1cc59ccdcf45ae0d53383d6585466a65e5c54c7a7f2458dc9d9dd494fd421497

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