Skip to main content

A modern and efficient OSC Client/Server implementation

Project description

OSCPy
=====

/!\ This is very much a work in progress /!\

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 import OSCClient

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

TODO:
- 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
- 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.2.0.tar.gz (163.4 kB view details)

Uploaded Source

Built Distribution

oscpy-0.2.0-py2.py3-none-any.whl (10.5 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for oscpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 60f93d735f6984833028f38907fceb5ee21b693b8524b91f9ab26df59ab37efc
MD5 1dac4447359edafa2d7631ae8fc4db0e
BLAKE2b-256 02e0f7ea8de4e7c2aab0c86dc095bcf6a0ddceb68bf7dc71fb5c1505337dbca9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for oscpy-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3124ae6a96713c18f52fd753889d371b28809d3f8c5b92dedcd97745acfffdef
MD5 9d6de3fce79ce648afc67dc3a681bd45
BLAKE2b-256 a12a032cf33441c0cc7e7db5518b06a971c3299951b103094dc52a1ca1636b17

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