Skip to main content

Open Sound Control server and client implementations in pure python.

https://github.com/attwad/python-osc/actions/workflows/python-test.yml/badge.svg

Current status

This library was developed following the OpenSoundControl Specification 1.0 and is currently in a stable state.

Features

  • UDP and TCP blocking/threading/forking/asyncio server implementations

  • UDP and TCP clients, including asyncio support

  • TCP support for 1.0 and 1.1 protocol formats

  • int, int64, float, string, double, MIDI, timestamps, blob, nil OSC arguments

  • simple OSC address<->callback matching system

  • support for sending responses from callback handlers in client and server

  • extensive unit test coverage

  • basic client and server examples

Documentation

Available at https://python-osc.readthedocs.io/.

Installation

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

https://img.shields.io/pypi/v/python-osc.svg
$ pip install python-osc

Examples

Simple client

"""Small example OSC 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 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=5005,
      help="The port the OSC server is listening on")
  args = parser.parse_args()

  client = udp_client.SimpleUDPClient(args.ip, args.port, timeout=10)

  for x in range(10):
    client.send_message("/filter", random.random())
    time.sleep(1)

Simple server

"""Small example OSC server

This program listens to several addresses, and prints some information about
received packets.
"""
import argparse
import math

from pythonosc.dispatcher import Dispatcher
from pythonosc import osc_server

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

def print_compute_handler(unused_addr, 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.map("/filter", 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, timeout=10)
  print("Serving on {}".format(server.server_address))
  server.serve_forever()

Building bundles

from pythonosc import osc_bundle_builder
from pythonosc import osc_message_builder

bundle = osc_bundle_builder.OscBundleBuilder(
    osc_bundle_builder.IMMEDIATELY)
msg = osc_message_builder.OscMessageBuilder(address="/SYNC")
msg.add_arg(4.0)
# Add 4 messages in the bundle, each with more arguments.
bundle.add_content(msg.build())
msg.add_arg(2)
bundle.add_content(msg.build())
msg.add_arg("value")
bundle.add_content(msg.build())
msg.add_arg(b"\x01\x02\x03")
bundle.add_content(msg.build())

sub_bundle = bundle.build()
# Now add the same bundle inside itself.
bundle.add_content(sub_bundle)
# The bundle has 5 elements in total now.

bundle = bundle.build()
# You can now send it via a client with the `.send()` method:
client.send(bundle)

License?

Unlicensed, do what you want with it. (http://unlicense.org)

Metadata

Release files for python-osc 1.10.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-osc 1.10.2
File Size Uploaded
python_osc-1.10.2.tar.gz 33.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-osc 1.10.2
File Interpreter ABI Platform
python_osc-1.10.2-py3-none-any.whl Python 3 none any Details

Total release size: 79.2 kB

Release files / python_osc-1.10.2.tar.gz

Download URL python_osc-1.10.2.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
732548f4f467dda9f890a6b0b3bfb085ab117f4bd38a45a58d2ca0f3bd6a546d
BLAKE2b-256 checksum
How to use checksums
a179094503dc039c8ba9cead01f4b5e163d795a6a502563d3a31f35d20a1ecf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / python_osc-1.10.2-py3-none-any.whl

Download URL python_osc-1.10.2-py3-none-any.whl
Size 45.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
018b28e1cc06427c2c3d695f4e8d87d0caecfe604ff889acc45235cfd94183a2
BLAKE2b-256 checksum
How to use checksums
1fa2ce26e437e36707f0da839dd88b072413825ea8986b73ce7b5c4f3cd1b7f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

1.10.2 This release

2 release files

1.9.3

2 release files

1.9.2

2 release files

1.9.1

2 release files

1.9.0

2 release files

1.8.3

2 release files

1.8.2

2 release files

1.8.1

2 release files

1.8.0

2 release files

1.7.7

2 release files

1.7.6

2 release files

1.7.4

1 release file

1.7.2

1 release file

1.7.0

1 release file

1.6.8

1 release file

1.6.7

1 release file

1.6.6

1 release file

1.6.4

1 release file

1.6.3

1 release file

1.6.2

2 release files

1.6.1

2 release files

1.6

2 release files

1.5

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4

1 release file

1.3

1 release file

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page