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.8.tar.gz (5.9 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.8-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: easy_udp-0.1.8.tar.gz
  • Upload date:
  • Size: 5.9 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.8.tar.gz
Algorithm Hash digest
SHA256 e61d73841b42dc16f1c48e925042d51d68394a75271606ab9140f1e0040c29c5
MD5 17d352f2d6bebaed84cfbed1054a5f7b
BLAKE2b-256 aa0bf5b20c0054a46f43f7cb19956f1c01698509467fd31debb90405b72b6d5a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: easy_udp-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 394d549927af7283b376753dac47a3c1f417c9e5b8caa49ebfe5f9ffb6eb66f8
MD5 ba31a82532f471bd1360b7da66927509
BLAKE2b-256 49dc1cc066120eeffe44d52e5b792f834e77e4261f3b1a3d974d5b2a2eec9fee

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