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/UDPReceiverand safe socket lifecycle (close(),__enter__,__exit__). - Enabled
SO_REUSEADDRfor faster restarts. - Added
recv_timeout_s(optional) toUDPReceiverto 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 inUDPReceiver). - 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:
UDPSenderandUDPReceiverwith support fornumpy.ndarray,str, andint.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_udp-0.1.9.tar.gz.
File metadata
- Download URL: easy_udp-0.1.9.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
689ca242eed5d820ac7e2a1479e1ab3978834a1ec35596f1503c739106b55261
|
|
| MD5 |
639e2b116d5edd6248b63f3d55a65f80
|
|
| BLAKE2b-256 |
d02654a02d2f1c4079bb55b5e7d6e5bc552e2e8a2896d1c8a791830cc0b2ae7c
|
File details
Details for the file easy_udp-0.1.9-py3-none-any.whl.
File metadata
- Download URL: easy_udp-0.1.9-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c93f3dec899eec36e68bd1b93da13e8b3cb5f369aa8dd8582e45aa4edf4b9a9
|
|
| MD5 |
7a1ec00493ee2dd67c83ffd6d0d4f111
|
|
| BLAKE2b-256 |
4539562bb271f09f8ea278e9773ba56bcd568ea2ed5707f0ed9f8f7002e5660e
|