Metadata-Version: 2.4
Name: aiolo
Version: 4.2.0
Summary: asyncio-friendly Python bindings for liblo
Home-page: https://github.com/elijahr/aiolo
Author: Elijah Shaw-Rutschman
Author-email: elijahr+aiolo@gmail.com
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Framework :: AsyncIO
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: License :: OSI Approved :: BSD License
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: examples
Requires-Dist: pyaudio; extra == "examples"
Provides-Extra: test
Requires-Dist: uvloop; extra == "test"
Requires-Dist: netifaces; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-asyncio; extra == "test"
Provides-Extra: dev
Requires-Dist: uvloop; extra == "dev"
Requires-Dist: netifaces; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-instafail; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-python
Dynamic: summary

# aiolo

[![CI](https://github.com/elijahr/aiolo/actions/workflows/ci.yml/badge.svg)](https://github.com/elijahr/aiolo/actions/workflows/ci.yml)
[![PyPI version](https://img.shields.io/pypi/v/aiolo.svg)](https://pypi.org/project/aiolo/)
[![Python versions](https://img.shields.io/pypi/pyversions/aiolo.svg)](https://pypi.org/project/aiolo/)
[![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)

asyncio-friendly Python bindings for [liblo](http://liblo.sourceforge.net/), an implementation of the Open Sound Control (OSC) protocol for POSIX systems.

## Installation

Install liblo:

OS X: `brew install liblo`

Ubuntu: `apt-get install liblo7 liblo-dev`

Then:

```shell
pip install aiolo
```

## Examples

One of the many beautiful things in Python is support for operator overloading. aiolo embraces this enthusiastically to offer the would-be OSC hacker an intuitive programming experience for objects such as `Message`, `Bundle`, `Route`, and `Sub`.

### [Simple echo server](https://github.com/elijahr/aiolo/blob/master/examples/echo_server.py)

```python
import asyncio

from aiolo import Address, Midi, Server


async def main():

    server = Server(port=12001)
    server.start()

    # Create endpoints

    # /foo accepts an int, a float, and a MIDI packet
    foo = server.route('/foo', [int, float, Midi])
    ex = server.route('/exit')

    address = Address(port=12001)

    for i in range(5):
        address.send(foo, i, float(i), Midi(i, i, i, i))

    # Notify subscriptions to exit in 1 sec
    address.delay(1, ex)

    # Subscribe to messages for any of the routes
    subs = foo.sub() | ex.sub()

    async for route, data in subs:
        print(f'echo_server: {str(route.path)} received {data}')
        if route == ex:
            await subs.unsub()

    server.stop()


if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())
```


### [MultiCast](https://github.com/elijahr/aiolo/blob/master/examples/multicast.py)

```python
import asyncio
import random

from aiolo import MultiCast, MultiCastAddress, Route, Server


async def main():
    # Create endpoints for receiving data
    foo = Route('/foo', str)
    ex = Route('/exit')

    # Create a multicast group
    multicast = MultiCast('224.0.1.1', port=15432)

    # Create a cluster of servers in the same multicast group
    cluster = []
    for i in range(10):
        server = Server(multicast=multicast)
        # Have them all handle the same route
        server.route(foo)
        server.route(ex)
        server.start()
        cluster.append(server)

    address = MultiCastAddress(server=random.choice(cluster))

    # Send a single message from any one server to the entire cluster.
    # The message will be received by each server.
    address.send(foo, 'hello cluster')

    # Notify subscriptions to exit in 1 sec
    address.delay(1, ex)

    # Listen for incoming strings at /foo on any server in the cluster
    subs = foo.sub() | ex.sub()
    async for route, data in subs:
        print(f'{route} got data: {data}')
        if route == ex:
            await subs.unsub()

    for server in cluster:
        server.stop()


if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

```

For additional usage see the [examples](https://github.com/elijahr/aiolo/blob/master/examples) and [tests](https://github.com/elijahr/aiolo/blob/master/test.py).

## Supported platforms

Tested across Ubuntu and macOS on Python 3.10, 3.11, 3.12, and 3.13 with liblo 0.30–0.36.

## Contributing

Pull requests are welcome, please file any issues you encounter.

## Changelog

See [CHANGELOG.md](CHANGELOG.md) for full release history.
