Skip to main content

Easy UDP communication library

Project description

Easy UDP

Easy UDP is a Python package that simplifies UDP communication. It provides convenient classes for UDP Sender and Receiver implementations.

Installation

pip install easy-udp

Usage

UDP Sender

from easy_udp import UDPSender
import numpy as np

# Create UDP sender instance
udp_sender = UDPSender(host="localhost", port=12345)

# Sending data
print("Sending: 123")
udp_sender.send(123)

print("Sending: Hello, World!")
udp_sender.send("Hello, World!")

img = np.random.randint(0, 255, (1280, 720, 3), dtype=np.uint8)
print("Sending: img", img)
udp_sender.send(img)

# Send arbitrary Python object (picklable)
class Foo:
    def __init__(self, x):
        self.x = x

obj = {"a": 1, "b": [1, 2, 3], "foo": Foo(5)}
udp_sender.send(obj)

UDP Receiver

from easy_udp import UDPReceiver
import numpy as np

# Create UDP receiver instance
udp_receiver = UDPReceiver(host="localhost", port=12345)

# receive data
while True:
    received_data = udp_receiver.receive()
    if received_data is not None:
        if isinstance(received_data, np.ndarray):
            received_data = received_data.reshape((1280, 720, 3))
            print("Received: img", received_data)

        if isinstance(received_data, str):
            print("Received: str", received_data)

        if isinstance(received_data, int):
            print("Received: int", received_data)

        # Any other type — it's likely an arbitrary Python object
        else:
            print("Received: object", type(received_data), received_data)

You can also use context managers for automatic socket cleanup:

from easy_udp import UDPSender

with UDPSender(host="localhost", port=12345) as sender:
    sender.send("hello")

UDPReceiver supports optional timeout to avoid busy-waiting:

from easy_udp import UDPReceiver

receiver = UDPReceiver(host="localhost", port=12345, recv_timeout_s=1.0)
data = receiver.receive()  # returns None on timeout

Changelog

0.1.8

  • Added context manager support for UDPSender/UDPReceiver and safe socket lifecycle (close(), __enter__, __exit__).
  • Enabled SO_REUSEADDR for faster restarts.
  • Added recv_timeout_s (optional) to UDPReceiver to prevent busy-waiting; added small collection window in non-blocking mode.
  • Adjusted fragmentation to MTU-safe payloads (~1400 bytes) to avoid IP fragmentation and reduce packet loss.
  • Added support for sending arbitrary Python objects via pickle (falls back in UDPSender.send() and handled in UDPReceiver).
  • Improved error messages and type hints; minor README updates and examples.

Security note: pickle is unsafe with untrusted sources. Only enable/use object transfer in trusted environments.

0.1.7

  • Initial public API: UDPSender and UDPReceiver with support for numpy.ndarray, str, and int.

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

easy_udp-0.1.10.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

easy_udp-0.1.10-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file easy_udp-0.1.10.tar.gz.

File metadata

  • Download URL: easy_udp-0.1.10.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for easy_udp-0.1.10.tar.gz
Algorithm Hash digest
SHA256 790071f1f0b2cab7d1c1cde97638934308c44c5016dc7198588b955c117e9ca7
MD5 1085f9f84d6e0815c9a8e1ce1ff3929d
BLAKE2b-256 75543b5e4f4a421374ccd79ee2be2ca6558da40b243d2cefd2b72d89d94666fc

See more details on using hashes here.

File details

Details for the file easy_udp-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: easy_udp-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for easy_udp-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 80505d6ed4e11c9d56ff335a8ecafe9952315f36c245eda255a09e83603144ed
MD5 f8dfefdedbbf75c2f2ed33b3be293af7
BLAKE2b-256 4e2ef95d56e360bf6d899eaebd198b64062aa88eb273b9838cd74e3f849966d3

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