torq.py
Strongly timed concurrent Python on one logical clock — audio/synth, MIDI/DMX cues, deterministic sim ticks, and lab protocols share the same rational Time / Dur timeline.
now advances only when shreds yield a duration (or you advance / run / SimClock.step / frame). No wall-clock sleep for logical waits. Timing, cues, sim, and lab are pure-Python; optional native _vm / _audio ship as binary wheels when available.
Status: research / alpha (
0.2.x). APIs may evolve. PyPI projecttorqpy; importtorq; brand torq.py.
Install
pip install torqpy
On platforms with a matching binary wheel (manylinux, macOS, Windows release builds), that install already includes torq._vm and torq._audio. Timing / shreds / cues / SimClock / lab need no native code either way.
import torq # package name on PyPI is torqpy; import is torq
Editable checkout:
git clone https://github.com/valid22/torq.py.git
cd torq.py
pip install -e ".[dev]"
python3 -m unittest discover -s torq/tests
Optional native extensions ([native])
torq.audio and torq.native_clock need the compiled extensions. Prefer a binary wheel from PyPI. When no matching wheel is available (or you are on a git checkout), build both _vm and _audio from the included sources with setuptools:
# toolchain: C++17 compiler, Python headers, PortAudio (e.g. portaudio19-dev / brew install portaudio)
TORQ_NATIVE=1 pip install 'torqpy[native]'
# from a git checkout:
TORQ_NATIVE=1 pip install -e '.[native]'
TORQ_NATIVE=1 tells the setuptools Extension build to compile; the [native] extra documents that you want the native feature set. In-place helpers remain as bash torq/native/build_vm.sh / build_audio.sh if you prefer not to reinstall.
Quickstart
junnu’s four-hit metronome — deterministic, no wall sleep:
from torq import Clock, ms, spork
clock = Clock()
hits = []
def junnu_metro():
for _ in range(4):
hits.append(clock.now)
yield 500 * ms
clock.spork(junnu_metro())
clock.run()
# hits at 0, 0.5s, 1s, 1.5s
Laddu’s polite meow on the same clock (needs _audio from a wheel or torqpy[native]):
from torq import Clock, Time, ms, spork
from torq.audio import AudioEngine, write_wav
engine = AudioEngine(48_000)
osc = engine.SinOsc(440)
env = engine.ADSR(0.01, 0.1, 0.3, 0.2)
osc >> env >> engine.Gain(0.35) >> engine.dac
clock = Clock(sample_rate=48_000)
def laddu_meow():
env.keyOn()
yield 300 * ms
env.keyOff()
yield 300 * ms
with clock:
spork(laddu_meow)
buf = engine.render_while(clock, until=Time(0) + 600 * ms)
write_wav("beep.wav", buf, engine.sample_rate)
Features by domain
| Domain | Entry points | Highlights |
|---|---|---|
| Core clock / shreds | Clock, Time, Dur, spork, yield / await (~d) |
Exact rational time; concurrent shreds in ordinary Python |
| Ergonomics | with clock:, now, wait, ~d, t ^ d, Pat / p["x-x-"], @shred |
Context-local clock; patterns; unary + spork |
| Audio / synth | torq.audio.AudioEngine |
In-process UGens + embedded STK (Clarinet…Saxofony with controlChange, NRev, JCRev, PRCRev, Chorus) on torq.py’s sample clock; offline WAV; optional PortAudio |
| MIDI / DMX cues | torq.cues.CueSchedule |
Note/CC/program/bend/aftertouch/DMX stamps; deterministic events(); SMF/MidiFile export via to_midi/save_midi (optional mido; DMX skipped); stub frames / mido / composite live sinks |
| Sim ticks | SimClock(dt) |
Fixed-timestep step / accumulator frame + pause / timescale / reset / clear_hooks / lerp; replay-stable |
| Lab protocols | torq.lab.Protocol / Session |
Stimuli, DAQ windows, planned inject steps, multi-trial sessions; JSON-safe Timeline/session export; stubs |
MIDI / DMX cues
from torq import Clock, ms, second
from torq.cues import CueSchedule
clock = Clock()
cues = CueSchedule(clock)
def junnu_phrase():
cues.program_change(0, 12)
cues.pitch_bend(0, 8192) # center (0–16383)
cues.note_on(0, 60, 100)
yield 250 * ms
cues.pitch_bend(0, 9000)
cues.aftertouch(0, 72) # channel pressure (alias: channel_pressure)
yield 250 * ms
cues.note_off(0, 60)
cues.cc(0, 1, 64)
yield 250 * ms
cues.dmx(1, {1: 255, 2: 128})
yield second
clock.spork(junnu_phrase())
clock.run()
events = cues.events() # deterministic offline list
# optional: cues.save_midi("junnu.mid") # needs mido; DMX omitted from SMF
Sim ticks
from torq import SimClock, second, spork, now
sim = SimClock(second / 60)
log = []
def junnu():
while True:
log.append(("junnu", sim.now))
yield sim.dt
@sim.on_step
def laddu_hook():
log.append(("Laddu", now(), sim.tick))
with sim:
spork(junnu)
sim.step(3)
# Accumulator frame: fixed updates + render alpha
@sim.on_update
def junnu_physics():
pass
@sim.on_render
def laddu_draw():
blend = sim.alpha # Fraction in [0, 1)
x = sim.lerp(0, 10) # uses alpha when t omitted
sim.frame(sim.dt / 2)
sim.pause() # junnu freezes the chase; Laddu inspects alpha
sim.frame(sim.dt) # no-op while paused
sim.resume()
sim.timescale = 2.0 # frame banks elapsed * 2; step ignores timescale
sim.reset() # replay from origin; hooks stay, shreds clear
sim.off_render(laddu_draw) # Laddu unsubscribes draw before a second scene
sim.clear_hooks() # drop remaining update/render hooks
Lab protocol
from torq import Clock, ms
from torq.lab import Protocol, Session, StubDAQ, StubDriver
proto = (
Protocol("meow-trial")
.mark("ready")
.window("adc", duration=100 * ms, channels=("mic",), rate=1000, advance=False)
.stimulus(
"meow",
duration=20 * ms,
onset=25 * ms,
payload={"who": "Laddu", "line": "ttl0"},
advance=False,
)
.inject({"mic": 0.75}, at=30 * ms, window="adc") # planned stub sample
.wait(100 * ms)
.mark("done")
)
timeline = proto.plan() # offline, no hardware (includes inject edges)
clock = Clock()
driver, daq = StubDriver(lines=("ttl0",)), StubDAQ(sample_rate=1000)
timeline, fired = proto.run(clock, driver=driver, daq=daq)
# daq.records[0].by_channel["mic"][30] == 0.75
# Multi-trial session: N runs on one clock, stubs reset between trials
session = Session(proto, isi=50 * ms)
session.run(Clock(), trials=3, driver=StubDriver(lines=("ttl0",)), daq=StubDAQ())
# session.to_json() — JSON-safe snapshot (rational Time/Dur strings)
Documentation
| Doc | Contents |
|---|---|
| docs/api.md | Public API surface |
| docs/strongly-timed-python.md | Timing model & type rules |
| docs/torq-examples.md | Copy-paste timing snippets |
| docs/torq-sim.md | SimClock step / frame / pause / timescale / reset / clear hooks / lerp |
| docs/torq-cues.md | MIDI / DMX cue schedules |
| docs/torq-lab.md | Stimuli, DAQ windows, protocols, multi-trial sessions |
| docs/torq-audio.md | UGens, stereo, live, STK |
| docs/torq-ugen-roadmap.md | Audio coverage roadmap |
| docs/compare.md | Related systems (peers, not the headline) |
| llms.txt | Agent-oriented install & patterns |
Contributing
Issues and PRs welcome at github.com/valid22/torq.py.
pip install -e ".[dev]"
python3 -m unittest discover -s torq/tests
Optional native extensions (used by audio + some tests): TORQ_NATIVE=1 pip install -e '.[native]' (or the torq/native/build_*.sh helpers).
License
Apache-2.0. Vendored STK under torq/native/stk/ carries its own MIT-style license (Cook & Scavone).
Metadata
Release files for torqpy 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torqpy-0.3.0.tar.gz | 148.3 kB | With provenance | Details for torqpy-0.3.0.tar.gz |
Built distributions (wheels)
Total release size: 8.8 MB
Release files / torqpy-0.3.0.tar.gz
| Download URL | torqpy-0.3.0.tar.gz |
|---|---|
| Size | 148.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ae58d2856a7927ebff032193536f3a83dea8abf15083a8b2ee73f6d0cdeafdd
|
|
BLAKE2b-256 checksum How to use checksums |
6538eac8de45a5002aa0f45242cf220142185ee4e90b9a4d4b1667e96aba8fcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp313-cp313-win_amd64.whl
| Download URL | torqpy-0.3.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 434.6 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
29e1b09faac1cb70041b107edfb14e55d149a475d21074a9f54f160f7f82cca1
|
|
BLAKE2b-256 checksum How to use checksums |
034940756df7f9f6a0bafb53d71e838eb615702c0ec630dd1ab243f8d578035a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | torqpy-0.3.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
358c90e72fd2eb57416bf5843a641e00a6841abb9f9bb11a073abd8bdb52f508
|
|
BLAKE2b-256 checksum How to use checksums |
bc303e216b142935ec2a0a77841cc0ce827b58525bc0bd311a701dc3a884a29e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | torqpy-0.3.0-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 255.1 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bb575de6d2b95f4ce65fdd19c5c4330e61c0b0ffaded5029c9539a197d04aba3
|
|
BLAKE2b-256 checksum How to use checksums |
165ddfa4d64dcbd985fb81322597ef18b793418fb7f4db786a0632ac3a880b94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp312-cp312-win_amd64.whl
| Download URL | torqpy-0.3.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 434.5 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
a849d4b5cfa6c5338c07510852cd77012addcf15b7e8d0b30cfbbbe7bd08fbd7
|
|
BLAKE2b-256 checksum How to use checksums |
f2fca70b4e9865b446906bd303779641bf41292eeb6c42a0e1d0b4a8f0ef37e7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | torqpy-0.3.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
2e431b0a3363b058061005c12689830ae4d85862b2cc820dbfee121641545d3b
|
|
BLAKE2b-256 checksum How to use checksums |
27e71d174537a27408e9c9f121f26d91af41299e89fed98a9ed5fd023fb4672e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | torqpy-0.3.0-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 255.1 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
631f820e7a3bc4be90fdfc1ff83bac568a005b3cb933e36b9543f6ec27b7a762
|
|
BLAKE2b-256 checksum How to use checksums |
36fdc176d558cf28c69c0c0d8d0eac0a7a7c799ef4526b1c885a8fd13cde2b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp311-cp311-win_amd64.whl
| Download URL | torqpy-0.3.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 434.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
47876ae12376aee4e6ae9e11f1f688813a4aeae05e35698ab481858d866fc801
|
|
BLAKE2b-256 checksum How to use checksums |
7c2a0dc1737cc1daa095faa69a98bf8082ab4febf726b039c909c87e8ea4762f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | torqpy-0.3.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
8ecd362f54729d598d40cf358145a539be9e19d399d4bf6a6e453646c2e99e22
|
|
BLAKE2b-256 checksum How to use checksums |
b44dc11f26f3ab41bd24c29353ec3b36043694e59b599150adcb642db289f28b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | torqpy-0.3.0-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.6 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b4ee5a7964517fad6517105d09a7c6091cfe7fa80e9e50c86e478173261ed6cd
|
|
BLAKE2b-256 checksum How to use checksums |
c44d3d31cd36b0631c5276e3e1d0618055ccfd899677efb10e92d7945fddedbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp310-cp310-win_amd64.whl
| Download URL | torqpy-0.3.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 434.6 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
128f70709b95a1370267af76af3b4cc878e359dadee0adddf5f0bc927725915e
|
|
BLAKE2b-256 checksum How to use checksums |
d6d67707bb829a1fb5df68a20771ae4c9bffdaf2124a0aea470cde23d7768af0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | torqpy-0.3.0-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1956fafd2f016b2a52f2dbdb885fa2420d0ede49b9a4e21c35df59fdf9297d70
|
|
BLAKE2b-256 checksum How to use checksums |
4df97cc707bc87438e533e83ff0f09033cbab7af2b22d00a811b74e8683a19c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logRelease files / torqpy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | torqpy-0.3.0-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.6 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
77c50b84be7d06254c05664a26da09b958329e633dabfd33a29f07bf211c8a2f
|
|
BLAKE2b-256 checksum How to use checksums |
be44bd14af90a2cfe1c6766e73298bd771af2d24c8489167ef1ff56021941855
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logSecurity for torqpy 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 13 files in this release have been uploaded with provenance metadata.
Attestation for torqpy-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.