Skip to main content

Open Sound Control server and client implementations in pure Python

Project description

Open Sound Control server and client implementations in pure python (3.3+).

Current status

This library was developped following the specifications at http://opensoundcontrol.org/spec-1_0 and is currently in a stable state.

Features

  • UDP blocking/threading/forking server implementations

  • UDP client

  • int, float, string, blob OSC arguments

  • simple OSC address<->callback matching system

  • extensive unit test coverage

  • basic client and server examples

Installation

python-osc is a pure python library that has no external dependencies, to install it just use pip (prefered):

$ pip install python-osc

or from the raw sources for the development version:

$ python setup.py test
$ python setup.py install

Examples

Simple client

"""
This program sends 10 random values between 0.0 and 1.0 to the /filter address,
waiting for 1 seconds between each value.
"""
import argparse
import random
import time

from pythonosc import osc_message_builder
from pythonosc import udp_client


if __name__ == "__main__":
  parser = argparse.ArgumentParser()
  parser.add_argument("--ip", default="127.0.0.1",
      help="The ip of the OSC server")
  parser.add_argument("--port", type=int, default=8000,
      help="The port the OSC server is listening on")
  args = parser.parse_args()

  client = udp_client.UDPClient(args.ip, args.port)

  for x in range(10):
    msg = osc_message_builder.OscMessageBuilder(address = "/filter")
    msg.add_arg(random.random())
    msg = msg.build()
    client.send(msg)
    time.sleep(1)

Simple server

import argparse
import math

from pythonosc import dispatcher
from pythonosc import osc_server

def print_volume_handler(args, volume):
  print("[{0}] ~ {1}".format(args[0], volume))

def print_compute_handler(args, volume):
  try:
    print("[{0}] ~ {1}".format(args[0], args[1](volume)))
  except ValueError: pass

if __name__ == "__main__":
  parser = argparse.ArgumentParser()
  parser.add_argument("--ip",
      default="127.0.0.1", help="The ip to listen on")
  parser.add_argument("--port",
      type=int, default=5005, help="The port to listen on")
  args = parser.parse_args()

  dispatcher = dispatcher.Dispatcher()
  dispatcher.map("/debug", print)
  dispatcher.map("/volume", print_volume_handler, "Volume")
  dispatcher.map("/logvolume", print_compute_handler, "Log volume", math.log)

  server = osc_server.ThreadingOSCUDPServer(
      (args.ip, args.port), dispatcher)
  print("Serving on {}".format(server.server_address))
  server.serve_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

python-osc-1.2.zip (25.4 kB view details)

Uploaded Source

python-osc-1.2.tar.gz (15.7 kB view details)

Uploaded Source

File details

Details for the file python-osc-1.2.zip.

File metadata

  • Download URL: python-osc-1.2.zip
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-osc-1.2.zip
Algorithm Hash digest
SHA256 c02f747754f47cba01b98dbdad7f33fccba2df0870137f660e5591479d1a548d
MD5 d481a493231b3aa78d1e29d4dc4f614c
BLAKE2b-256 1aa6ecf90a52f00a9a7c27a03b8d2b4acb448d364634e0ad8e7b4cb3a1c6a405

See more details on using hashes here.

File details

Details for the file python-osc-1.2.tar.gz.

File metadata

  • Download URL: python-osc-1.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for python-osc-1.2.tar.gz
Algorithm Hash digest
SHA256 a63ff909ba5e528f451e1de7363347723db1ff611ca6aaff1e19a0629a12fcea
MD5 36c28372db96db6eac5c554146bbf8e1
BLAKE2b-256 3db3209cd640562641a38bf336dd498cfc667789c6d5f75512318088fa6d8f17

See more details on using hashes here.

Supported by

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