cycsound
Cython bindings for the Csound 6.x API.
Overview
cycsound is a Cython wrapper for the Csound audio synthesis library, providing Python bindings for the csound.h C API. It offers an alternative to the default ctypes-based ctcsound.py wrapper included with Csound.
Features
- 98% API coverage of the Csound C API (216/219 functions)
- Context manager support for automatic resource cleanup
- GIL release for all blocking operations (enables true multi-threading)
- Static linking support on macOS (standalone wheels without Csound installation)
- Platform support: macOS, Linux, Windows
- CLI for common operations (play, render, check, info, eval)
Installation
pip install cycsound
Building From Source
Prerequisites:
- Python >= 3.9
- Csound 6.x installed:
- macOS: CsoundLib64.framework in
/Library/Frameworks/ - Linux:
libcsound64-devpackage - Windows: Csound6_x64 in
C:/Program Files/
- macOS: CsoundLib64.framework in
# Clone the repository
git clone https://github.com/yourusername/cycsound.git
cd cycsound
# Install in development mode
make sync
# Or install directly
pip install .
Building Wheels
# Dynamic linking (requires Csound at runtime)
make wheel
# Static linking - standalone wheel (macOS only)
make wheel-static
Command-Line Interface
cycsound includes a CLI for common Csound operations:
# Play a CSD file
cycsound play myscore.csd
# Render to audio file
cycsound render myscore.csd # Creates myscore.wav
cycsound render -o output.wav myscore.csd # Specify output file
cycsound render -f flac -r 48000 myscore.csd # FLAC format, 48kHz
# Validate CSD syntax
cycsound check myscore.csd
# Show Csound version info
cycsound info
cycsound info -v # Verbose output
# Get help
cycsound --help
cycsound play --help
CLI Commands
| Command | Description |
|---|---|
play <file> |
Play CSD file in real-time |
render <file> |
Render CSD to audio file |
check <file> |
Validate CSD syntax |
info |
Show Csound version |
eval <code> |
Evaluate orchestra code |
Common Options
| Option | Description |
|---|---|
-q, --quiet |
Suppress output |
-o, --output |
Output file/device |
-h, --help |
Show help |
Quick Start
import cycsound
# Using context manager (recommended)
with cycsound.Csound() as cs:
cs.set_option("-odac") # Real-time audio output
cs.set_option("-d") # Suppress displays
cs.compile_orc("""
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
asig oscil 0.5, 440
outs asig, asig
endin
""")
cs.read_score("i1 0 2")
cs.run() # Performs entire score
# cleanup() called automatically on exit
# Or with manual control
with cycsound.Csound() as cs:
cs.compile_csd("myscore.csd")
cs.start()
while not cs.perform_ksmps():
# Process each k-cycle
pass
API Reference
Module-level Functions
| Function | Description |
|---|---|
get_version() |
Returns Csound version (e.g., 6180 for 6.18.0) |
get_api_version() |
Returns API version |
get_size_of_myflt() |
Returns size of MYFLT type (4 or 8) |
initialize(flags=0) |
Initialize Csound library (rarely needed) |
set_opcode_dir(path) |
Set opcode directory override |
Csound Class
Core methods for audio synthesis:
# Context manager support
with cycsound.Csound() as cs:
# ... use cs ...
# cleanup() called automatically
# Compilation
cs.compile_orc(orc_string) # Compile orchestra code
cs.compile_csd(filename) # Compile CSD file
cs.compile_csd_text(csd_string) # Compile CSD from string
cs.read_score(score_string) # Read score events
# Performance
cs.run() # Perform entire score (convenience method)
cs.start() # Prepare for performance
cs.perform() # Perform entire score (blocks)
cs.perform_ksmps() # Perform one control period
cs.perform_buffer() # Perform one buffer
cs.stop() # Stop performance
cs.cleanup() # Close audio/MIDI devices
cs.reset() # Reset for new performance
# Configuration
cs.set_option(option) # Set command-line option
cs.get_sr() / cs.get_kr() # Get sample/control rate
cs.get_ksmps() / cs.get_nchnls() # Get ksmps/channels
# Channels
cs.set_control_channel(name, value)
cs.get_control_channel(name)
cs.set_string_channel(name, value)
cs.get_string_channel(name)
Enums
# Status codes (return values from Csound operations)
cycsound.Status.SUCCESS # 0 - Operation succeeded
cycsound.Status.ERROR # -1 - General error
cycsound.Status.INITIALIZATION # -2 - Initialization error
cycsound.Status.PERFORMANCE # -3 - Performance error
cycsound.Status.MEMORY # -4 - Memory allocation error
cycsound.Status.SIGNAL # -5 - Signal received
# File types
cycsound.FileType.WAVE # WAV audio
cycsound.FileType.FLAC # FLAC audio
cycsound.FileType.OGG # OGG Vorbis audio
cycsound.FileType.UNIFIED_CSD # Csound CSD file
cycsound.FileType.STD_MIDI # Standard MIDI file
# ... and 60+ more file type constants
# Message types
cycsound.Msg.DEFAULT # Standard message
cycsound.Msg.ERROR # Error message
cycsound.Msg.WARNING # Warning message
# Message colors
cycsound.Color.FG_RED # Foreground colors
cycsound.Color.FG_GREEN
cycsound.Color.FG_BOLD # Text attributes
Development
Setup
# Initial setup
make sync
# Rebuild after code changes
make build
# Run tests
make test # All tests
make test-cli # CLI tests only
Available Make Targets
| Target | Description |
|---|---|
make / make build |
Build/rebuild the extension |
make sync |
Initial environment setup |
make test |
Run test suite |
make wheel |
Build wheel (dynamic linking) |
make wheel-static |
Build standalone wheel (macOS) |
make release |
Build static wheels for all Python versions |
make check |
Check distribution with twine |
make publish |
Publish to PyPI |
make publish-test |
Publish to TestPyPI |
make clean |
Remove build artifacts |
make help |
Show all targets |
Static Build Requirements (macOS)
For make wheel-static, install dependencies via Homebrew:
brew install libsndfile flac opus libvorbis libogg mpg123 lame
Rationale
This project provides an alternative to the default ctypes-based wrapper. Cython offers several advantages over ctypes:
- Better performance for tight loops
- Direct C-level access to Csound internals
- Ability to release the GIL for true multi-threading
- Static linking for self-contained distribution
For more details, see this comparison of wrapping approaches.
Status
- Wrap enough to play arbitrary CSD files
- Build static variant as wheel (macOS only)
- 98% coverage of csound.h API (216/219 functions)
- GIL release for all blocking operations
- scikit-build-core based build system
- Context manager support
- Test suite (36 tests: core API, CLI, channels, threading, enums)
- CI/CD with cibuildwheel (GitHub Actions)
- Complete wrapping of csound.h (remaining: 3 va_list callbacks)
- Include plugin support in wheel
- Feature parity with ctcsound.py
Related Projects
License
See LICENSE file.
Metadata
Release files for cycsound 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| cycsound-0.1.0-cp314-cp314-macosx_15_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 15.0+ ARM64 | Details |
| cycsound-0.1.0-cp313-cp313-macosx_15_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 15.0+ ARM64 | Details |
| cycsound-0.1.0-cp312-cp312-macosx_15_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 15.0+ ARM64 | Details |
| cycsound-0.1.0-cp311-cp311-macosx_15_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 15.0+ ARM64 | Details |
| cycsound-0.1.0-cp310-cp310-macosx_15_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 15.0+ ARM64 | Details |
Total release size: 10.3 MB
Release files / cycsound-0.1.0-cp314-cp314-macosx_15_0_arm64.whl
| Download URL | cycsound-0.1.0-cp314-cp314-macosx_15_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.14 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
eb203e5a2486894cbd7dffef2f706e271411f20ab5095960745d32f9f308b0ec
|
|
BLAKE2b-256 checksum How to use checksums |
c91efbdea684dc99f18a90c5af2cb2061eaf478d4f6f148beab1c8522076a76d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / cycsound-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | cycsound-0.1.0-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
70d1fead85acf9bb975a731327c846da0f3899c5ef4a342a7a524dbbdb8e0f12
|
|
BLAKE2b-256 checksum How to use checksums |
c4cbb5e14ba75af79156611944d12cce61e16686c282555d4096be9c0193ce9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / cycsound-0.1.0-cp312-cp312-macosx_15_0_arm64.whl
| Download URL | cycsound-0.1.0-cp312-cp312-macosx_15_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.12 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5e17bcdbcf65d1fbc28ea5b7ce53617c0248a916d294b81f0a67b401b1c078e3
|
|
BLAKE2b-256 checksum How to use checksums |
1388ff321d15ca67fde8993e1c4fe78d237322e385b6a59f33a9fde476c94411
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / cycsound-0.1.0-cp311-cp311-macosx_15_0_arm64.whl
| Download URL | cycsound-0.1.0-cp311-cp311-macosx_15_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.11 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
795d365f4bebdf2f6fef619b2a0d6072a0a151e8b3dd74bb65a90435f489a1d0
|
|
BLAKE2b-256 checksum How to use checksums |
d4fcc55436d89891a3429e0e3f66717ed42b2f163c4746a606a319eed00ffca3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / cycsound-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
| Download URL | cycsound-0.1.0-cp310-cp310-macosx_15_0_arm64.whl |
|---|---|
| Size | 2.1 MB |
| Tags | CPython 3.10 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7b6b60e28fda399c4289ae49a70cb14d57a057fbb73ea1d99d337102b330c719
|
|
BLAKE2b-256 checksum How to use checksums |
92987a7ca291aea5698c3fedec7b8678520e930817d884cd5c58a3452776d490
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for cycsound 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.