Skip to main content

A modern and efficient OSC Client/Server implementation

Project description

OSCPy
=====

A modern implementation of OSC for python2/3.

Goals:
- python2.7/3.6+ compatibility (can be relaxed more on the python3 side if needed, but nothing before 2.7 will be supported)
- fast
- easy to use
- robust (returns meaningful errors in case of malformed messages, always do the right thing on correct messages)
- separation of concerns (message parsing vs communication)
- sync and async compatibility (threads, asyncio, trio…)
- clean and easy to read code

features:
- serialize and parse OSC data types/Messages/Bundles
- a thread based udp server to open sockets and bind callbacks on osc addresses on them
- a simple client


usage:
------

Server (thread)
```python
from oscpy.server import OSCThreadServer as OSC
from time import sleep

def callback(values):
print("got values: {}".format(values))

osc = OSCThreadServer()
sock = osc.listen(address='0.0.0.0', port=8000, default=True)
osc.bind(b'/address', callback)
sleep(1000)
osc.stop()
```

or you can use the decorator API.

Server (thread)
```python
from oscpy.server import OSCThreadServer as OSC
from time import sleep

osc = OSCThreadServer()
sock = osc.listen(address='0.0.0.0', port=8000, default=True)

@osc.address(b'/address')
def callback(values):
print("got values: {}".format(values))

sleep(1000)
osc.stop()
```

Servers are also client, in the sense they can send messages and answer to
messages from other servers
```python
from oscpy.server import OSCThreadServer as OSC
from time import sleep

osc_1 = OSCThreadServer()
osc_1.listen(default=True)

@osc_1.address(b'/ping')
def ping(*values):
print("ping called")
if True in values:
cont.append(True)
else:
osc_1.answer(b'/pong')

osc_2 = OSCThreadServer()
osc_2.listen(default=True)

@osc_2.address(b'/pong')
def pong(*values):
print("pong called")
osc_2.answer(b'/ping', [True])

osc_2.send_message(b'/ping', [], *osc_1.getaddress())

timeout = time() + 1
while not cont:
if time() > timeout:
raise OSError('timeout while waiting for success message.')
```


Server (async) (TODO!)
```python
from oscpy.server import OSCThreadServer as OSC

with OSCAsyncServer(port=8000) as OSC:
for address, values in OSC.listen():
if address == b'/example':
print("got {} on /example".format(values))
else:
print("unknown address {}".format(address))
```

Client
```python

from oscpy.client import OSCClient

osc = OSCClient(address, port)
for i in range(10):
osc.send_message(b'/ping', [i])
```

TODO:
- [x] address matching (outside of the currently supported *exact* matching)
- real support for timetag (currently only supports optionally dropping late bundles, not delaying those with timetags in the future)
- support for additional arguments types
- an asyncio-oriented server implementation
- [x] performances assessment (profiling and comparison with other implementations)
- examples & documentation

license
-------

MIT


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

oscpy-0.3.0.tar.gz (164.9 kB view details)

Uploaded Source

Built Distribution

oscpy-0.3.0-py2.py3-none-any.whl (9.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file oscpy-0.3.0.tar.gz.

File metadata

  • Download URL: oscpy-0.3.0.tar.gz
  • Upload date:
  • Size: 164.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for oscpy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1ad68e61839a31afaafc9d8792d5b2246f85883aa7d87d33a9676a6ffee053c5
MD5 d46494fb3bcb744deb4bea3d0118756e
BLAKE2b-256 98363349abc043de16615cbe9215f056ba3351dab822980127ff5b4d9453c764

See more details on using hashes here.

File details

Details for the file oscpy-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for oscpy-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8f58914e3078f01a9992bdf8ed72979df244cb2f9ddf5eec911c368e19f29178
MD5 c921ad6ed78676f9dae4aa38689ac662
BLAKE2b-256 57529fb6f8d3bd84acec34ba0f60a2cea12ac3a6f726dc7bd956ece2f0ba843e

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