Skip to main content

py2tosc

Generate and edit TouchOSC layouts from Python.

Tests PyPI License

py2tosc is a rewrite of tosclib by Alberto Valdez, whose work established the original mapping between the .tosc format and Python that this library is built on. The API is new and incompatible, but the knowledge of the format -- the control types, the property tables, the message layouts, and some of the tests and examples -- came from there, and is carried over with thanks. Original copyright is retained in LICENSE.

Disclaimer: This project has no relation to Hexler, the developer of TouchOSC. Back up your layouts before editing them with third party tools.

Documentation

$ pip install py2tosc

No dependencies. Python 3.10 or newer.

What it does

A .tosc file is a zlib-compressed XML tree. py2tosc reads that tree into plain Python objects, lets you edit them, and writes it back out -- accurately enough that loading a layout and saving it again reproduces the editor's own bytes exactly, in both the compressed and exported forms.

import py2tosc

doc = py2tosc.load("mixer.tosc")

for fader in doc.find_all(type="FADER"):
    fader.color = "#e76f51"
    fader.corner_radius = 2.0

doc.save("mixer-restyled.tosc")

Building one from scratch:

import py2tosc
from py2tosc import layout

doc = py2tosc.Document.new(frame=(0, 0, 1024, 768))

strip = py2tosc.group(name="strip", frame=(0, 0, 1024, 768))
doc.add(strip)

for index, fader in enumerate(layout.row(strip, "FADER", sizes=8)):
    fader.name = f"ch{index + 1}"
    fader.messages.append(py2tosc.OscMessage())

doc.save("mixer.tosc")

Design

Module Holds
enums TouchOSC's own vocabulary: control types, property types, conversions
properties Property, Frame, Color, and the snake_case to camelCase mapping
messages Value, OscMessage, MidiMessage, LocalMessage, GamepadMessage and their parts
defaults The default property set for each control type
control Control, the node model, plus a factory per control type
codec Reading and writing the .tosc XML dialect, CDATA included
document Document, load, save, dumps
layout Row, column and grid arrangement, in plain arithmetic

Property keys are camelCase in the file because that is what TouchOSC stores. The Python API is snake_case and translates at the boundary, so control.corner_radius addresses the cornerRadius key.

Contributing

$ make install     # install the package and dev dependencies
$ make test        # run the test suite
$ make docs-serve  # serve the documentation with live reload

make help lists the rest. The project uses uv for environments, building and publishing.

Releasing

  1. Bump version in pyproject.toml and __version__ in src/py2tosc/__init__.py -- a test fails if they disagree.

  2. Date the release's section in CHANGELOG.md.

  3. make release-check, then make tag and git push origin vX.Y.Z.

  4. make publish-test to rehearse against TestPyPI, then make publish CONFIRM=1.

Publishing is manual and irreversible: a filename PyPI has accepted cannot be reused even after a delete, and no workflow re-checks the tag or the tree first. That makes make release-check in step 3 the only gate, so run it on a clean checkout. Both publish targets rebuild dist/ from scratch and validate it with twine check --strict before uploading, and both need credentials in ~/.pypirc or TWINE_USERNAME/TWINE_PASSWORD.

Documentation is published the same way, with make docs-deploy. Nothing deploys it automatically.

Bug reports and pull requests are welcome, including for the documentation.

Download files

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

Source Distribution

py2tosc-0.1.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py2tosc-0.1.0-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file py2tosc-0.1.0.tar.gz.

File metadata

  • Download URL: py2tosc-0.1.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for py2tosc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9abd66927ae6131f8d8afff6ae97ff9bad8f160de9a486c75bf0e739594b0759
MD5 d65d8330650157949a978ee1b10ab1b1
BLAKE2b-256 d8de07bfa8c79a0f3d9d8c94d54c418b0cb4235bf546766563f8803acd27b3c8

See more details on using hashes here.

File details

Details for the file py2tosc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py2tosc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for py2tosc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1d73b6be5a3f78b0795f65c4c62aee587b5e1b9e3d6b0e1b5784dcf037e499f3
MD5 f0cff6fc3830c8f623ed8c93be158a76
BLAKE2b-256 5dc379e81718182436a0606f4ec0154f38f2e5b8501b83a0eb1bf9dc3326d9b4

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 Sentry Error logging StatusPage Status page