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.
| Module | Contents | Rust |
|---|---|---|
open_stomp | Device, Update, DeviceState, Event, Origin, Module, ParamDef, Preset, ModuleState, Settings, Msg, Assembler, is_stomp_port, is_ble_port, USB_ID, __version__ | crate root |
open_stomp.device | Device, Update | device |
open_stomp.state | DeviceState, Event, Origin, Looper, Drum, Tuner, looper_state_name | state |
open_stomp.records | Preset, ModuleState, Settings, preset_label, PRESET_COUNT, PRESET_LEN, DEFAULT_CHAIN | records |
open_stomp.catalog | Module, ParamDef, drum_pattern_name, NOTES, DRUM_STYLES, OD_MODELS, AMP_MODELS, CAB_MODELS, MOD_MODELS, DELAY_MODELS, REVERB_MODELS, MICS, POSITIONS | catalog |
open_stomp.midi | Msg, Assembler, hex, frame, MFR, UID, PEDAL_CH, HOST_CH | midi |
open_stomp.midi.req | version(), product(), settings(), cur_state(), drum(), looper(), tuner(), edit_buffer(), chain(), ir_slot(i), preset(i), user_amp(i) | midi::req |
open_stomp.midi.host | cc, program, head, param, volume, page, looper_button, tuner, chain, preset_name, preset_write, save_preset, settings_write, LOOP_* | midi::host |
open_stomp.queue | RequestQueue, Request, Done, handshake, follow_up | queue |
open_stomp.capture | parse, Entry | capture |
open_stomp.pack | pack, unpack | pack |
open_stomp.upload | Chunk, Reassembler, UserAmpInfo, user_amp_upload, user_amp_delete, user_ir_upload, user_ir_name, data_frames, check, floats_to_bytes, bytes_to_floats, constants | upload |
open_stomp.nam | Model, Converted, convert, excitation, official_excitation, pedal_level_db, TONE_BINS, FFT_SIZE, NORMALISED_LEVEL_DB | nam, nam::convert |
open_stomp.ir | ConvertedIr, convert, load_wav, save_wav, resample, IR_TAPS, SAMPLE_RATE, PEDAL_TAPS | ir |
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
| Topic | Rust | Python |
|---|---|---|
| Module variants | Module::OdFx, Module::Amp | Module.OD_FX, Module.AMP (an int-like enum: int(Module.EQ) == 7, hashable) |
| Module info | name(), models(), head_cc(), param_ccs(), index(), is_effect() | label, models, head_cc, param_ccs, index, is_effect (properties) |
| Origin | Origin::Pedal, Origin::Host | Origin.PEDAL, Origin.HOST |
| Event category | Category::Effect(Module) and so on; category.label() | Strings ("effect", …); ev.module, ev.label |
| Engine settings | Config { .. } with Durations | Keyword arguments to Device(...), in seconds |
| Updates | enum Update | One Update class; kind says which fields are set |
| Receiving | recv() returns Result | recv(timeout=None) returns None on timeout; for u in dev: |
| Stopping | Drop the Device | close() or a with block |
| Feeding state | state.apply(&bytes, origin) | state.apply(data, origin), or state.feed(update) |
| Preset chain | [u8; 8] of module indices | list[Module] |
| Preset module | module(m) → Option<&ModuleState>, module_mut(m) | module(m) → a ModuleState copy; set_module, set_param |
| Derived values | input_trim_db(), cents_offset(), state_name(), sample_rate() | Properties of the same names |
| Signal chain | set_chain(&[u8]) ignores an invalid order | set_chain(list[Module]) raises ValueError |
| NAM import | import_nam_file, import_nam_file_with, import_nam_file_as | import_nam_file(slot, path, measure="optimised", normalise=True) |
| IR import | import_ir_file, import_ir_file_with | import_ir_file(slot, path, method="optimised") |
| NAM conversion | convert, convert_with, convert_measured, normalise_level | nam.convert(model_or_path, excitation=None, measure="app", normalise=False) |
| IR conversion | ir::convert(&Wav), Wav | ir.convert(path, method="app"), ir.load_wav, ir.save_wav |
| Constants | convert::N, ir::PEDAL_IR_TAPS, ir::IR_SAMPLE_RATE | nam.FFT_SIZE, ir.PEDAL_TAPS, ir.SAMPLE_RATE |
| Queue times | Instant | Seconds since the queue was created; None = now |
| Queue input | on_message(&Msg), follow_up(&Msg) | on_message(data), follow_up(data) with raw bytes |
| Messages | enum Msg | One 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_irandupload.user_amp_read/user_ir_read(reading a slot back).nam::optimise: the optimiser'sOptions,optimise,simulate(usemeasure="optimised").nam::convertextras:convert_optimisedwith progress,upload_data,pedal_irs,official_app_locations.blemidi,Device::spawn_with_waker, theCommandenum,state::chain_label,ir::app_gain,ir::slot_name.
Only in Python
DeviceState.feed(update),Deviceas a context manager and iterator,Device.closed.Preset.set_module,Preset.set_param,copy()(andcopy.copy/copy.deepcopy),Settings.copy().
Conventions
- Bytes in: every argument that takes MIDI data accepts
bytes,bytearrayor a list of ints. Bytes out: alwaysbytes. - 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 indicesIndexError, file problemsOSError, and any call on a closedDeviceRuntimeError. - Builders that can't apply return
None, e.g.host.head(Module.LOOP, …). - Snapshots: attributes return copies.
state.live,state.presets[3]andpreset.modulesare copies; changing one never changes the model (more).
Threads and Ctrl-C
- The engine runs on its own thread.
recv, iteration,closeand the end of awithblock 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
.pyistubs andpy.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| Test | Checks |
|---|---|
test_protocol.py | Packing, parsing, reassembly, command builders (captured bytes), catalogue, record encode/decode, copy semantics |
test_captures.py | The 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.py | The engine end to end through replay, timeouts, close semantics |
test_upload.py | Upload framing against the captured NAM and IR imports |
test_nam.py | NAM inference and conversion from Python (the Rust tests cover accuracy in depth) |
test_ir.py | WAV round trip, resampling, IR conversion |
- Layout:
bindings/python/src/*.rs(one file per Rust module),python/open_stomp/(__init__.pyand the.pyistubs),tests/,examples/. - Version: the Python package version is the workspace version in the root
Cargo.toml.
