Skip to main content

pyquist

pyquist provides basic utilities for low-level computer music programming in Python and NumPy.

pyquist is designed for learning and is the teaching library for CMU's 15-322 Intro to Computer Music. Its primary purpose is to provide a barebones foundation for working with audio in Python, e.g., allocating sample buffers, audio file decoding and playback. Accordingly, it intentionally lacks a lot of functionality found in full-fledged computer music programming frameworks, such as a rich collection of unit generators.

Want to try it without installing anything? Open In Colab

Quick example

import numpy as np
import pyquist as pq

# A 1-second, 440 Hz sine wave at CD quality.
sr = 44100
t = np.arange(sr) / sr
audio = pq.Audio(0.5 * np.sin(2 * np.pi * 440 * t), sample_rate=sr)

pq.play(audio)        # play through default output (or notebook widget)
pq.plot(audio)        # waveform
pq.plot_spec(audio)   # spectrogram

Loading and transforming:

from pyquist.paths import TEST_DATA_DIR

riff = pq.Audio.from_file(
    TEST_DATA_DIR / "388954__fullmetaljedi__blues-riff-in-g-nylon.wav"
)
clip = riff.segment(offset=5.0, duration=3.0).resample(8000)
pq.play(clip)

Rendering a Score with a custom instrument. An instrument is called as instrument(**event.kwargs) — declare the kwargs you use and absorb the rest with **kwargs:

from pyquist.score import Score, BasicMetronome
from pyquist.helper import pitch_to_frequency

def sine_instrument(pitch, duration, **kwargs):
    sr = 44100
    t = np.arange(int(duration * sr)) / sr
    freq = pitch_to_frequency(pitch)
    return pq.Audio(0.3 * np.sin(2 * np.pi * freq * t) * np.exp(-3 * t), sample_rate=sr)

score = Score([
    (0, {"pitch": 60, "duration": 0.5}),
    (1, {"pitch": 64, "duration": 0.5}),
    (2, {"pitch": 67, "duration": 0.5}),
])
pq.play(score.render(sine_instrument, metronome=BasicMetronome(bpm=120)))

Real-time audio with a Stream, which calls your function on each short block of audio as it plays. The callback fills block in place, at full scale: like pq.play, a stream is safe=True by default, which turns its output down to -20 dBFS.

import time

class Sine:
    def __init__(self, frequency):
        self.frequency = frequency
        self.time = 0.0

    def callback(self, block):
        t = self.time + np.arange(len(block)) / block.sample_rate
        block.samples[:, 0] = np.sin(2 * np.pi * self.frequency * t)
        self.time += len(block) / block.sample_rate

with pq.Stream(Sine(440).callback):
    time.sleep(2.0)  # plays until the `with` block exits

With input channels, block arrives holding the microphone signal, so a callback that does nothing is a passthrough (use headphones): pq.Stream(lambda block: None, num_input_channels=1).

For a guided walkthrough — visualization, MIDI parsing, scores, instruments, a real-time piano — open examples/HelloPyquist.ipynb or run it in Colab.

Installation

Requires Python 3.10 or later.

macOS

brew install python@3.10          # or 3.11, 3.12, 3.13
python3.10 -m venv .venv
source .venv/bin/activate
pip install --upgrade pyquist

If pq.play(...) is silent, give Terminal (or your IDE) microphone/audio access in System Settings → Privacy & Security → Microphone.

Linux

Install Python and the PortAudio system library that sounddevice wraps:

# Debian / Ubuntu
sudo apt install python3 python3-venv libportaudio2

# Fedora
sudo dnf install python3 python3-virtualenv portaudio

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pyquist

Windows

Install Python (3.10 or later, with "Add Python to PATH" checked), then open Command Prompt:

python -m venv .venv
.venv\Scripts\activate.bat
pip install --upgrade pyquist

From source

For hacking on pyquist itself:

git clone https://github.com/gclef-cmu/pyquist.git
cd pyquist
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev,notebook]"
pre-commit install

Pick default audio devices

Once installed, the pyquist CLI (also available as pq) lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):

pyquist devices
pyquist play test

Or, from Python, for the current session only:

pq.list_devices()
pq.set_output_device("Speakers")  # device ID, or part of its name

Run notebooks

pip install jupyter ipykernel ipywidgets
python -m ipykernel install --user --name=pyquist --display-name "Pyquist"
cd examples
jupyter notebook

Then open HelloPyquist.ipynb and select the Pyquist kernel.

Acknowledgements

Inspired in part by:

Metadata

Release files for pyquist 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyquist 0.3.0
File Size Uploaded Provenance Actions
pyquist-0.3.0.tar.gz 1.9 MB With provenance Details for pyquist-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyquist 0.3.0
File Interpreter ABI Platform Actions
pyquist-0.3.0-py3-none-any.whl Python 3 none any Details for pyquist-0.3.0-py3-none-any.whl

Total release size: 3.8 MB

Release files / pyquist-0.3.0.tar.gz

Download URL pyquist-0.3.0.tar.gz
Size 1.9 MB
Tags Source
SHA-256 checksum
How to use checksums
4015a50e9b61bc6322a6c43ec10ab219e5d8a2afe2e981fc284fd8838e6129bb
BLAKE2b-256 checksum
How to use checksums
078582b812e0c907b84943eba76a50a8783f48a6749ccead0ae5d5982e786410
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 Nov 2, 2026.

Transparency log

Release files / pyquist-0.3.0-py3-none-any.whl

Download URL pyquist-0.3.0-py3-none-any.whl
Size 1.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
55480b4dcd1a7c9f2420a959cfdcdc567c9d89acbeacd38ef7044765d0722368
BLAKE2b-256 checksum
How to use checksums
a02763463938416d6dff65873fd7bea1a1217c3809cbb0c445be2998c30838bb
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 Nov 2, 2026.

Transparency log

Security for pyquist 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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pyquist-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 Nov 2, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page