Skip to content

Python API ​

Reference for the open_stomp Python package: its module layout, how names differ from the Rust crate, and the conventions it follows. The guides show every task in both languages; the full signatures are in the typed .pyi stubs.

Module layout ​

The package mirrors the Rust crate. The most used types are also importable from open_stomp directly.

ModuleContentsRust
open_stompDevice, Update, DeviceState, Event, Origin, Module, ParamDef, Preset, ModuleState, Settings, Msg, Assembler, is_stomp_port, is_ble_port, USB_ID, __version__crate root
open_stomp.deviceDevice, Updatedevice
open_stomp.stateDeviceState, Event, Origin, Looper, Drum, Tuner, looper_state_namestate
open_stomp.recordsPreset, ModuleState, Settings, preset_label, PRESET_COUNT, PRESET_LEN, DEFAULT_CHAINrecords
open_stomp.catalogModule, ParamDef, drum_pattern_name, NOTES, DRUM_STYLES, OD_MODELS, AMP_MODELS, CAB_MODELS, MOD_MODELS, DELAY_MODELS, REVERB_MODELS, MICS, POSITIONScatalog
open_stomp.midiMsg, Assembler, hex, frame, MFR, UID, PEDAL_CH, HOST_CHmidi
open_stomp.midi.reqversion(), product(), settings(), cur_state(), drum(), looper(), tuner(), edit_buffer(), chain(), ir_slot(i), preset(i), user_amp(i)midi::req
open_stomp.midi.hostcc, program, head, param, volume, page, looper_button, tuner, chain, preset_name, preset_write, save_preset, settings_write, LOOP_*midi::host
open_stomp.queueRequestQueue, Request, Done, handshake, follow_upqueue
open_stomp.captureparse, Entrycapture
open_stomp.packpack, unpackpack
open_stomp.uploadChunk, Reassembler, UserAmpInfo, user_amp_upload, user_amp_delete, user_ir_upload, user_ir_name, data_frames, check, floats_to_bytes, bytes_to_floats, constantsupload
open_stomp.namModel, Converted, convert, excitation, official_excitation, pedal_level_db, TONE_BINS, FFT_SIZE, NORMALISED_LEVEL_DBnam, nam::convert
open_stomp.irConvertedIr, convert, load_wav, save_wav, resample, IR_TAPS, SAMPLE_RATE, PEDAL_TAPSir

Submodules are real modules, so import open_stomp.midi and from open_stomp.midi.host import cc work like any package.

Naming differences from Rust ​

TopicRustPython
Module variantsModule::OdFx, Module::AmpModule.OD_FX, Module.AMP (an int-like enum: int(Module.EQ) == 7, hashable)
Module infoname(), models(), head_cc(), param_ccs(), index(), is_effect()label, models, head_cc, param_ccs, index, is_effect (properties)
OriginOrigin::Pedal, Origin::HostOrigin.PEDAL, Origin.HOST
Event categoryCategory::Effect(Module) and so on; category.label()Strings ("effect", …); ev.module, ev.label
Engine settingsConfig { .. } with DurationsKeyword arguments to Device(...), in seconds
Updatesenum UpdateOne Update class; kind says which fields are set
Receivingrecv() returns Resultrecv(timeout=None) returns None on timeout; for u in dev:
StoppingDrop the Deviceclose() or a with block
Feeding statestate.apply(&bytes, origin)state.apply(data, origin), or state.feed(update)
Preset chain[u8; 8] of module indiceslist[Module]
Preset modulemodule(m) → Option<&ModuleState>, module_mut(m)module(m) → a ModuleState copy; set_module, set_param
Derived valuesinput_trim_db(), cents_offset(), state_name(), sample_rate()Properties of the same names
Signal chainset_chain(&[u8]) ignores an invalid orderset_chain(list[Module]) raises ValueError
NAM importimport_nam_file, import_nam_file_with, import_nam_file_asimport_nam_file(slot, path, measure="optimised", normalise=True)
IR importimport_ir_file, import_ir_file_withimport_ir_file(slot, path, method="optimised")
NAM conversionconvert, convert_with, convert_measured, normalise_levelnam.convert(model_or_path, excitation=None, measure="app", normalise=False)
IR conversionir::convert(&Wav), Wavir.convert(path, method="app"), ir.load_wav, ir.save_wav
Constantsconvert::N, ir::PEDAL_IR_TAPS, ir::IR_SAMPLE_RATEnam.FFT_SIZE, ir.PEDAL_TAPS, ir.SAMPLE_RATE
Queue timesInstantSeconds since the queue was created; None = now
Queue inputon_message(&Msg), follow_up(&Msg)on_message(data), follow_up(data) with raw bytes
Messagesenum MsgOne Msg class with kind ("cc", "pc", "nep", "notify", "short", "other"); a short frame's kind is short_kind

Not in Python ​

  • Device.read_user_amp / read_user_ir and upload.user_amp_read / user_ir_read (reading a slot back).
  • nam::optimise: the optimiser's Options, optimise, simulate (use measure="optimised").
  • nam::convert extras: convert_optimised with progress, upload_data, pedal_irs, official_app_locations.
  • blemidi, Device::spawn_with_waker, the Command enum, state::chain_label, ir::app_gain, ir::slot_name.

Only in Python ​

  • DeviceState.feed(update), Device as a context manager and iterator, Device.closed.
  • Preset.set_module, Preset.set_param, copy() (and copy.copy / copy.deepcopy), Settings.copy().

Conventions ​

  • Bytes in: every argument that takes MIDI data accepts bytes, bytearray or a list of ints. Bytes out: always bytes.
  • Indices are 0-based: preset 0 is P01 (records.preset_label(0) == "P01"); model 8 is shown as #09.
  • Errors: bad records and bad upload data raise ValueError, out-of-range indices IndexError, file problems OSError, and any call on a closed Device RuntimeError.
  • Builders that can't apply return None, e.g. host.head(Module.LOOP, …).
  • Snapshots: attributes return copies. state.live, state.presets[3] and preset.modules are copies; changing one never changes the model (more).

Threads and Ctrl-C ​

  • The engine runs on its own thread. recv, iteration, close and the end of a with block release the GIL, so other Python threads keep running.
  • Ctrl-C: blocking calls wake at least every 100 ms, so Ctrl-C raises KeyboardInterrupt.
  • Long conversions (nam.convert, Device.import_nam_file) release the GIL too.
  • Several threads can share one Device (one receiving, others sending commands).
  • Free-threaded Python is supported.

Type stubs ​

  • The package ships .pyi stubs and py.typed, so editors and type checkers see every signature and docstring.
  • The stubs are checked against the compiled module with stubtest.
  • Browse them on GitHub, or in Python:
python
import open_stomp
help(open_stomp.Device)

Tests and development ​

sh
cd bindings/python
python -m venv .venv && . .venv/bin/activate
pip install maturin pytest mypy
maturin develop                                            # build into the venv (re-run after Rust changes)
pytest                                                     # tests driven by ../../captures/logs
python -m mypy.stubtest open_stomp --ignore-missing-stub   # the .pyi stubs match the module
TestChecks
test_protocol.pyPacking, parsing, reassembly, command builders (captured bytes), catalogue, record encode/decode, copy semantics
test_captures.pyThe whole captured session applies cleanly; every record re-encodes byte for byte; the captured save as is rebuilt; the startup sync through RequestQueue against a fake pedal answering from the capture
test_device.pyThe engine end to end through replay, timeouts, close semantics
test_upload.pyUpload framing against the captured NAM and IR imports
test_nam.pyNAM inference and conversion from Python (the Rust tests cover accuracy in depth)
test_ir.pyWAV round trip, resampling, IR conversion
  • Layout: bindings/python/src/*.rs (one file per Rust module), python/open_stomp/ (__init__.py and the .pyi stubs), tests/, examples/.
  • Version: the Python package version is the workspace version in the root Cargo.toml.

MIT or Apache-2.0. Not affiliated with SORAN.