songtools
A Python DSL for composing music from code. Notes carry expression, structure carries time. No magic strings, no duplicate logic or state.
Install
uv add songtools
Requires Python 3.14+ and sounddevice (PortAudio backend).
Core idea
The library revolves around the Sound object. Use the @ operator to transform sounds:
sound @ Effect: Applies a DSP effect.sound @ Key: Applies a harmonic context.sound @ Degree: Applies a relative pitch shift based on a key.
Abstractions
| Name | What it is |
|---|---|
Sound |
The primary object. Contains samples and harmonic context. |
Buffer |
Low-level wrapper around a float array for audio data. |
Key |
Harmonic context: root + scale + quality. |
WavFile |
Utility for reading/writing 16-bit PCM WAV files. |
Operators
| Op | Meaning |
|---|---|
a + b |
Concatenation (a, then b) |
a * n |
Repetition (repeat a, n times) |
a & b |
Mixing (linear sum of buffers) |
a @ transform |
Transform (Effect, Key, or Degree) |
Vocabulary
- Notes/Degrees:
Degree.IthroughDegree.VII. - Scales:
Scale.MAJOR,Scale.MINOR,Scale.DORIAN. - Qualities:
Quality.TRIAD,Quality.SEVENTH,Quality.NINTH,Quality.SUS2,Quality.SUS4,Quality.POWER. - Roots:
KeyRoot.C,KeyRoot.CS, etc.
Effects
Chain effects on any Sound using @:
| Effect | What it does |
|---|---|
Gain(amount) |
Multiply amplitude |
Decay(duration) |
Exponential envelope (timedelta) |
LowPass(hertz) |
One-pole lowpass filter |
HighPass(hertz) |
One-pole highpass filter |
Echo(duration) |
Single-tap delay |
Delay(time, fb, mix) |
Feedback delay with dry/wet blend |
Gate(duration) |
Hard cut to length |
FadeIn(duration) |
Linear ramp up from silence |
FadeOut(duration) |
Linear ramp down to silence |
Reverse |
Reverse the buffer |
Drive(amount) |
Tanh saturation |
Clip(threshold) |
Hard-limit peaks |
Normalize(peak) |
Scale so the loudest sample = peak |
Tremolo(hertz, depth) |
Amplitude modulation |
BitCrush(bits) |
Reduce bit depth (lo-fi) |
Humanize(velocity) |
Subtle gain variation |
Quick start
from datetime import timedelta
from songtools.lib import (
Sound, Key, KeyRoot, Scale, Quality,
Degree, Decay, LowPass, WavFile
)
# Create a simple tone
tone = Sound.tone(440.0, 44100)
# Apply transformations and effects
# A C-Major chord sequence with a lowpass filter
melody = (tone @ Key(KeyRoot.C, Scale.MAJOR, Quality.TRIAD) @ Degree.I) @ LowPass(2000)
# Sequence notes
song = Sound.sequence(melody @ Decay(timedelta(seconds=0.5)), tone @ Decay(timedelta(seconds=0.2)), bpm=bpm)
# Play or Save
song.play()
WavFile("output.wav").write(song)
License
MIT
Metadata
Release files for songtools 0.5.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 |
|---|---|---|---|---|
| songtools-0.5.0.tar.gz | 6.7 kB | Without provenance | Details for songtools-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| songtools-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for songtools-0.5.0-py3-none-any.whl |
Total release size: 14.4 kB
Release files / songtools-0.5.0.tar.gz
| Download URL | songtools-0.5.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ed27972339b63d95d115a7e319d081b0494100cc0ace30c5d1b75168386fe751
|
|
BLAKE2b-256 checksum How to use checksums |
3907416bf47603bd92cb9d97237fd5c6e961520851449e53ecf8e8c64be8de77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / songtools-0.5.0-py3-none-any.whl
| Download URL | songtools-0.5.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a48d4bb418519ef30fe97665387a04561463bc00bcd997fd242453f93348c5da
|
|
BLAKE2b-256 checksum How to use checksums |
955d1c5002518dc0ed28e282dd8f3a5621ed28fb58ef40d315dece92a142661e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.31 {"installer":{"name":"uv","version":"0.11.31","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for songtools 0.5.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.