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.2.0.tar.gz (43.3 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.2.0-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for py2tosc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d2b49e65fefb72528deb5afc6a4483af37ef6417077201bb7caafbc9dc902e8f
MD5 ef6a718fa3da67ca8cad73ff8cffc846
BLAKE2b-256 93189b30da1a97f225b6d627148f1c862fc5886eef288ccae4c75c337598193c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py2tosc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 44.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b7cea0d756e2a175bb10447bd73ba7a59d8b9cd683b8ceace7c6055a502a8d8
MD5 edc5562ae45b2bd43f041ec817f3c41f
BLAKE2b-256 ad46b693c0b02faf0508f04e12344d071a9df5c7bd830ab3c087be161ccf8fb4

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