Skip to main content

Python library for gateways, networks, and devices.

Project description

gatenet 🛰️

BETA (0.1.0)

Installation

pip install gatenet

Features

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

codecov

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

Uploaded Python 3

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

Hashes for gatenet-0.1.0.tar.gz
Algorithm Hash digest
SHA256 64b047407adb8b144ea5be26c846b4d31fb680196f451a99496557a8e2932ad4
MD5 4f4b7cc3b4cb2705a36da3c952c59eec
BLAKE2b-256 b62f253181a9ed2cb430832a818059ffe35d64c1091b7091d1b1a8411e868e1b

See more details on using hashes here.

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

Hashes for gatenet-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a0334d2e7c822fc826ccdcf7db26e7a08a9cfae13dd12c3362815bd41e00cd7
MD5 edcaea01cb27159704cd26f3905a9dc6
BLAKE2b-256 79364f25abcc7360d0b2de5addcb4f236235c45130fcc228f63f560e80926677

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