Skip to main content

A better API for asynchronous UDP

Project description

AioUDP

Poetry Code style: black Ruff Imports: isort Checked with mypy codecov

Documentation Status CI PyPI - Python Version PyPI PyPI - License

A better API for asynchronous UDP

A websockets-like API for UDP

Here's an example echo server:

import asyncio
import signal

import aioudp


async def main():
    async def handler(connection):
        async for message in connection:
            await connection.send(message)

    # Optional. This is for properly exiting the server when Ctrl-C is pressed
    # or when the process is killed/terminated
    loop = asyncio.get_running_loop()
    stop = loop.create_future()
    loop.add_signal_handler(signal.SIGTERM, stop.set_result, None)
    loop.add_signal_handler(signal.SIGINT, stop.set_result, None)

    # Serve the server
    async with aioudp.serve("localhost", 9999, handler):
        await stop  # Serve forever

if __name__ == '__main__':
    asyncio.run(main())

And a client to connect to the server:

import asyncio

import aioudp


async def main():
    async with aioudp.connect("localhost", 9999) as connection:
        await connection.send(b"Hello world!")
        assert await connection.recv() == b"Hello world!"

if __name__ == '__main__':
    asyncio.run(main())

Installation

You can get this project via pip

$ pip install aioudp

Or, if you're using Poetry

$ poetry add aioudp

[!NOTE] This library provides no other abstractions over the existing UDP interface in asyncio other than the async/await-based API. This means there is no implicit protocol handled in this library such as QUIC. You must write your own, or find another library.

See also

  • AnyIO, a broader asynchronous networking and concurrency library for abstracting over any async IO implementation. It has a similar API (which I didn't know about before I wrote this library)
  • WebSockets, a library for Python to interact with WebSockets. Its API heavily inspired the design of AioUDP.
  • QUIC, a faster protocol similar to TCP, built on UDP.
  • AioQUIC, a Python implementation of QUIC.

License

Copyright © 2021, Bryan Hu

This project is licensed under the GNU GPL v3+.

In short, this means you can do anything with it (distribute, modify, sell) but if you were to publish your changes, you must make the source code and build instructions readily available.

If you are a company using this project and want an exception, email me at thatxliner@gmail.com and we can discuss.

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

aioudp-1.0.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

aioudp-1.0.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file aioudp-1.0.1.tar.gz.

File metadata

  • Download URL: aioudp-1.0.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1018-azure

File hashes

Hashes for aioudp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f1b6e24ff24c08d34165d0e6bce5fca0bce6c042df6e98c47f7c543f4b7b7c57
MD5 6da30a8b04132207e163227d32cd63ef
BLAKE2b-256 9e63adeecd6c8625de15c20aec266af29ed0dd612700aae26d67e1aa044f2618

See more details on using hashes here.

File details

Details for the file aioudp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aioudp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1018-azure

File hashes

Hashes for aioudp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40f3a2bc22c7719c44610d42e7b60b445e1118cd0a33daed7ecb91a4c80a0e63
MD5 b5cabebde972b68f5f3d0d0316ab0d9e
BLAKE2b-256 9a945dd3dacb9757bc4172c122524b67105214e498703b2fbf66fad5087fa2e2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page