A Cython wrapper for libpd (Pure Data) with built-in audio support
Project description
cypd: Cython wrapper for libpd
A Cython-based Python wrapper for libpd (Pure Data as an embeddable audio library) with built-in audio support via miniaudio.
Features
- Full libpd API: Comprehensive access to libpd functionality including patches, messaging, arrays, MIDI, and callbacks
- Built-in audio: Integrated miniaudio backend for easy audio playback
- Flexible architecture: Use the built-in audio or integrate your own audio system
- Thread-safe audio: Audio processing runs in a separate thread with proper
nogilhandling - Modern build system: Uses scikit-build-core with CMake
Installation
pip install cypd
Build from source
Prerequisites
- Python 3.10+
- uv (recommended) or pip
- CMake 3.15+
- C compiler (clang/gcc)
# Clone the repository
git clone https://github.com/shakfu/cypd.git
cd cypd
# Build libpd and miniaudio dependencies
./scripts/setup.sh
# Install with uv
uv sync
# Or install with pip
pip install -e .
Quick Start
Using the built-in audio
from cypd import audio
# Play a patch for 4 seconds
audio.play("my_patch.pd", "/path/to/patches", duration_ms=4000)
Manual control
import cypd
from cypd import audio
# Initialize libpd
cypd.init()
cypd.init_audio(1, 2, 44100) # 1 input, 2 outputs, 44100 Hz
# Initialize audio backend
audio.init_audio(44100, 1, 2)
# Open a patch
patch_id = cypd.open_patch("my_patch.pd", "/path/to/patches")
# Start audio and enable DSP
audio.start()
cypd.dsp(True)
# Let it play
audio.sleep(4000) # 4 seconds
# Cleanup
cypd.dsp(False)
audio.stop()
audio.terminate()
cypd.close_patch(patch_id)
Sending messages to Pure Data
import cypd
cypd.init()
patch_id = cypd.open_patch("my_patch.pd", ".")
# Send a bang
cypd.send_bang("my_receiver")
# Send a float
cypd.send_float("frequency", 440.0)
# Send a symbol
cypd.send_symbol("my_receiver", "hello")
# Send a list
cypd.send_list("my_receiver", 1, 2, 3, "foo", "bar")
# Send a typed message
cypd.send_message("my_receiver", "set", 1, 2, 3)
cypd.close_patch(patch_id)
Receiving messages from Pure Data
import cypd
def my_float_callback(receiver, value):
print(f"Received float {value} from {receiver}")
def my_bang_callback(receiver):
print(f"Received bang from {receiver}")
cypd.init()
cypd.set_float_callback(my_float_callback)
cypd.set_bang_callback(my_bang_callback)
# Subscribe to a sender
cypd.subscribe("my_sender")
# ... run your patch ...
cypd.unsubscribe("my_sender")
MIDI
import cypd
cypd.init()
patch_id = cypd.open_patch("my_synth.pd", ".")
cypd.init_audio(1, 2, 44100)
# Send MIDI note on (channel, pitch, velocity)
cypd.noteon(0, 60, 100) # Middle C, velocity 100
# Send MIDI note off
cypd.noteon(0, 60, 0) # velocity 0 = note off
# Control change
cypd.controlchange(0, 1, 64) # Modulation wheel
# Pitch bend
cypd.pitchbend(0, 0) # Center position
cypd.close_patch(patch_id)
Array access
import cypd
cypd.init()
patch_id = cypd.open_patch("with_array.pd", ".")
# Get array size
size = cypd.array_size("my_array")
print(f"Array size: {size}")
# Resize array
cypd.resize_array("my_array", 1024)
cypd.close_patch(patch_id)
API Reference
Initialization
init()- Initialize libpdinit_audio(in_channels, out_channels, sample_rate)- Initialize audio renderingrelease()- Shutdown libpd and release resources
Patches
open_patch(name, dir)- Open a patch, returns patch IDclose_patch(patch_id)- Close a patchadd_to_search_path(path)- Add to abstraction search pathclear_search_path()- Clear the search path
Audio
get_blocksize()- Get pd's block size (always 64)dsp(on)- Enable/disable DSP processing
Messaging
send_bang(receiver)- Send a bangsend_float(receiver, value)- Send a floatsend_symbol(receiver, symbol)- Send a symbolsend_list(receiver, *args)- Send a listsend_message(receiver, msg, *args)- Send a typed messagesubscribe(source)- Subscribe to messages from a senderunsubscribe(source)- Unsubscribe from a senderexists(receiver)- Check if a receiver exists
Callbacks
set_print_callback(func)- Set print hookset_bang_callback(func)- Set bang receive hookset_float_callback(func)- Set float receive hookset_symbol_callback(func)- Set symbol receive hookset_list_callback(func)- Set list receive hookset_message_callback(func)- Set typed message receive hook
MIDI
noteon(channel, pitch, velocity)- Send note oncontrolchange(channel, controller, value)- Send control changeprogramchange(channel, value)- Send program changepitchbend(channel, value)- Send pitch bendaftertouch(channel, value)- Send aftertouchpolyaftertouch(channel, pitch, value)- Send poly aftertouch
Arrays
array_size(name)- Get array sizeresize_array(name, size)- Resize an array
Audio Module (cypd.audio)
init_audio(sample_rate, channels_in, channels_out)- Initialize miniaudiostart()- Start audio playbackstop()- Stop audio playbackterminate()- Shutdown audiois_running()- Check if audio is runningsleep(milliseconds)- Sleep for durationplay(patch, dir, duration_ms, ...)- Convenience function to play a patchget_version()- Get miniaudio version string
Development
# Run tests
make test
# Build
make build
# Clean
make clean
Architecture
The project consists of two Cython extension modules:
_libpd: Core libpd wrapper providing the full API_audio: Miniaudio-based audio backend
The _audio module obtains a function pointer to libpd_process_float from _libpd at runtime, ensuring both modules share the same libpd instance (avoiding issues with static library symbol duplication).
License
See LICENSE file.
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cypd-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14t, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b86964ff33744943bd56bf67fccf2d487ad64a7ea6dd59f6b1bb2b216869a44
|
|
| MD5 |
d19625bcc1f12dcfc248c7d5d12d70b3
|
|
| BLAKE2b-256 |
79fbb9b0c9ff6bb192847ae2deb7b0ed418a883a31d2f969b4668bcdd2969487
|
File details
Details for the file cypd-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl
- Upload date:
- Size: 884.8 kB
- Tags: CPython 3.14t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c99c9fbb4e7393b1f3df416ac4eb432cf19f7f71146804f8778a91ef50bb66dc
|
|
| MD5 |
f80c2fe9a05cc9c65383e471d969059d
|
|
| BLAKE2b-256 |
a8e82a1f853dce1157718283fd44423023b7ec639e41d153f8d375f98c575502
|
File details
Details for the file cypd-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.14, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3914e483736fb1692ad65959bb580771e623265ec76265dd3f760510114872c3
|
|
| MD5 |
951a513d378ba41dfc2429d70ccef356
|
|
| BLAKE2b-256 |
834c2d01be8f8933e80cf1f94c53a61e0cddbe70d57bdfa7b911ba8bf6338b9d
|
File details
Details for the file cypd-0.1.0-cp314-cp314-macosx_15_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp314-cp314-macosx_15_0_arm64.whl
- Upload date:
- Size: 893.0 kB
- Tags: CPython 3.14, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6860e4b9ff5ddbed1565ca4e86701698f489efca32ac368f5b76a5154d7f43
|
|
| MD5 |
8fc3fe1fb7f3666c3e9535dcc5ab8d45
|
|
| BLAKE2b-256 |
5d44fb39290f29650115b23957592c6355b2452ade613a938595c3b48ce114d5
|
File details
Details for the file cypd-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 871.6 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6f21613aeaf990456c4d8e18742fa141af7c5cdbc92279be0cd67cfca6d27d7
|
|
| MD5 |
0b3e526a121625ee85f53efdc9587803
|
|
| BLAKE2b-256 |
1ade4f266b51ddcaa7079af9f75415cf922709132fc45e76a2b9271b26dd1f5f
|
File details
Details for the file cypd-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9fb28c4ebac48d6977979693b812b959ac33c369110a5743564d0edd434953a
|
|
| MD5 |
80a276b2e7e0aa7939de41d76d8672d4
|
|
| BLAKE2b-256 |
03f236ff770caab57102577c9015a4037f9ca1d13cc9be5cfffa480e383a1576
|
File details
Details for the file cypd-0.1.0-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 891.5 kB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d08a5f4f1ae56b4951ebf5564a0fccd7be0e854b9961a1d6486ccd13605de82
|
|
| MD5 |
cb38816f6ac3c48570226868987953f8
|
|
| BLAKE2b-256 |
51f3d100798bc5813fdcb0d033e4123336f89a8dc04811a8b12468e517301f17
|
File details
Details for the file cypd-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 870.8 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f99c83b6bab4e798bc67acb46b0d3e0db969a7466dbce52957f715820021b406
|
|
| MD5 |
4d0c11525334d169136c7357183032dc
|
|
| BLAKE2b-256 |
2b569477252079815197a585da691a36dc84d95ed2bd8c5c1ff455ab378dcf2b
|
File details
Details for the file cypd-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99f958b19a1d0f97b942b86337d3a07bba7e722e10858fa769528f1dd9b5c827
|
|
| MD5 |
426d1f84b4865de701ab9e33e05816ea
|
|
| BLAKE2b-256 |
6ddd26d786b436d672be59d3990165b9657918a7a834edd705d19e00c6fdaf1e
|
File details
Details for the file cypd-0.1.0-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 892.7 kB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5425501688aed402fa1bb8df230f36f3ac409ab08fcab6ed2900b0c355a437f6
|
|
| MD5 |
82853caec7dd8bd0a20cbe47e79c98a3
|
|
| BLAKE2b-256 |
35f8e76bef15b95714c6e2f8ce5446e498b163711794f30fbb4e9ddaa43d5af2
|
File details
Details for the file cypd-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 872.3 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9466de61b91088145e7daca30f5d06398b463fdef2c9233493f73b6ba14931a
|
|
| MD5 |
6aa276f8ddd01e24a28350cf82af2b7e
|
|
| BLAKE2b-256 |
083716241b49422dab72e46ebccbafd34b95f3cd6a0ddf95fb7e2295a15f5c53
|
File details
Details for the file cypd-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7d75889dcf658b9cb3c8879abb6f2ab462630877e806844b8401429cbe4acbf
|
|
| MD5 |
e1c23a88738bf42170720d7feb632664
|
|
| BLAKE2b-256 |
f522c548719060bbfb022570b8236aba828b1bcd5a41814f68eb89acf6fa8802
|
File details
Details for the file cypd-0.1.0-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 892.9 kB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dd3553996c8340ad005d3b7cadd6696105bf09116fc5f614eec6ff8e8bb3bc0
|
|
| MD5 |
b3da8570715c95be1b90a96606768534
|
|
| BLAKE2b-256 |
ae187d4d9d91e522532668bfbe7a1725f320dc4f7cee35e65cb9532db55f1e32
|
File details
Details for the file cypd-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 875.2 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0d144c69365d06cc8e682fd14cf85f04898943a661942616cbe9d79f2c85533
|
|
| MD5 |
3c947b95964ee281d0c9906c25561649
|
|
| BLAKE2b-256 |
c901b86c4c36d2747bc65544d1409300f49bede735ed56236d51135ee98cab0f
|
File details
Details for the file cypd-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
123b6cf3343485a1df21d723d90a589d7466ae3f8096735323bf10b2efeef82e
|
|
| MD5 |
42c0d3e5f3f7286bd087a4133757292d
|
|
| BLAKE2b-256 |
b46082f5061ed38b18fb033286210f44045b63909b4063f49550cab6daaf0d4f
|
File details
Details for the file cypd-0.1.0-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 893.3 kB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57b7b11b6f3a682e25c55abef6fc01e24e8115644898184ffed3847ed84d77cf
|
|
| MD5 |
efef7096c8cd28bd6b157e92181108be
|
|
| BLAKE2b-256 |
1c38c345c0bc5374d4bc9040a5006dbc652c8ce6b2536d538b8482fcff9e8323
|
File details
Details for the file cypd-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 875.5 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec695e0f2f927aab13556529376d75e3d2ac8a4e579f6737d439797340a1dedf
|
|
| MD5 |
8a83d0cf119b5862454078cbbc3fcbb8
|
|
| BLAKE2b-256 |
253cf79760e17903758be2eb504ae0cd2109671f06c2c06751b4f65590b43ed4
|
File details
Details for the file cypd-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: cypd-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd343b0f5dc339074024b8af1f35c875c66b8de93016864a9ed3264a84e135ee
|
|
| MD5 |
132c4916f455148ac3452e7ce952988f
|
|
| BLAKE2b-256 |
060c656c664538f7cb964529e3b89d04b526fcbf2d8a92f5540418d7e913d76a
|
File details
Details for the file cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 875.7 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66f58c109e151d7c73c2e5caeeeda52db81f3624e93151ee57228bc2a68f8590
|
|
| MD5 |
9619a3a61a929c4390579675e652b8e4
|
|
| BLAKE2b-256 |
54d7abbbf1317cf67d8a9bad334ae81cc2d22813b5485744fa9513e97c7462f9
|