Code-generated music: write blocks of code, export Spotify-ready audio
Project description
code-music
Code-generated music. Write Python, hear sound, export to Spotify.
Try it in your browser — no install needed.
Who are you?
| 🎧 Just want to listen | Start here → |
| 🎹 Want to make music (no theory needed) | Start here → |
| 🎼 Know your modes and want full control | Start here → |
| 💻 Want to understand or extend the code | Start here → |
What is this?
A Python library and tool set for generating music programmatically — from a single scale all the way to full multi-track songs with orchestral instruments, EDM synthesis, jazz arpeggios, and effects chains.
from code_music import Song, Track, Note, Chord, EffectsChain, scale, reverb, play
song = Song(title="My Track", bpm=120)
pad = song.add_track(Track(instrument="pad", volume=0.5))
lead = song.add_track(Track(instrument="piano", volume=0.8))
pad.add(Chord("A", "min7", 3, duration=8.0))
lead.extend(scale("A", "pentatonic", octave=5))
song.effects = {"pad": EffectsChain().add(reverb, room_size=0.7, wet=0.4)}
play(song) # hear it instantly
code-music my_track.py --flac # → Spotify-ready FLAC
Install
pip install code-music # from PyPI
pip install code-music[play] # + real-time playback (sounddevice)
Or develop from source:
git clone https://github.com/Talador12/code-music
cd code-music
make dev # creates .venv, installs deps, checks ffmpeg
make test # full pytest suite
Requires Python 3.11+. For MP3/FLAC/OGG export: brew install ffmpeg.
What's in the box
| Directory | What's there |
|---|---|
examples/ |
8 step-by-step tutorials: hello world → live coding |
songs/ |
140 full songs across 55+ genres |
samples/ |
100+ short instrument and technique demos |
scales/ |
31 guided scale demos (all 12 keys), plus arpeggio mode |
styles/ |
Theory profiles for 7 genres (deadmau5, Zedd, bebop, cinematic…) |
scripts/ |
Interactive scale/arp player with progress bar |
code_music/ |
The engine, synth, effects, export, notation, voice |
Play something right now
# Songs
make play-trance_odyssey # 90s uplifting trance
make play-tank_bebop # Cowboy Bebop big-band jazz
make play-deep_space_drift # Brian Eno ambient
make play-clarity_drive # Zedd-style festival EDM
make play-symphony_no1 # original orchestral movement
make preview-voice_pacing_demo # narration vs rap pacing demo
# Scales and key relationships
make play-scales
make play-scales-arp # same scales as arpeggios
make play-scales-group GROUP=world
make play-scale-circle_of_fifths # key relationship reference run
# Direct playback (no file written)
code-music songs/trance_odyssey.py --play
# Live coding: auto-render + play on every save
code-music songs/my_wip.py --watch --play
# Import and render a MIDI file
code-music dummy.py --import-midi my_track.mid -o remix.wav
# Generate a random song and play it (no script needed)
code-music --random
code-music --random jazz
# Generate a complete song from a genre template
from code_music import generate_song, detect_key, play
song = generate_song("lo_fi", bars=16, seed=42)
play(song)
# Analyze any song's key
root, mode, conf = detect_key(song)
print(f"{root} {mode} ({conf:.0%})")
Learn by example
The examples/ directory walks through the entire API step by step:
| # | Example | What you'll learn |
|---|---|---|
| 01 | hello_world.py |
Notes, tracks, Song basics |
| 02 | chords_and_scales.py |
Chord shapes, scale(), modes |
| 03 | effects_chain.py |
EffectsChain, reverb, delay, compress |
| 04 | arrangement.py |
Section, repeat, Song.arrange |
| 05 | track_transforms.py |
transpose, loop, split, merge, stretch, filter |
| 06 | midi_roundtrip.py |
Export to MIDI, import back, remix |
| 07 | json_save_load.py |
Song.export_json / Song.load_json |
| 08 | live_coding.py |
--watch --play for instant feedback |
| 09 | generative.py |
generate_song() — full AI-composed songs |
| 10 | analysis.py |
detect_key() — Krumhansl-Kessler key analysis |
code-music examples/01_hello_world.py --play # start here
code-music --random jazz # or just generate one
Export to Spotify
make spotify # renders all songs to dist/flac/ + prints upload link
Upload at https://artists.spotify.com → Music → Upload Track. Minimum: 30s, 44100 Hz stereo. FLAC preferred.
Sheet music
make notation-all # LilyPond (.ly), ABC (.abc), MusicXML (.xml) for every song
- LilyPond:
lilypond dist/notation/lily/trance_odyssey.ly→ PDF - ABC: paste
dist/notation/abc/tank_bebop.abcinto https://abc.rectanglered.com - MusicXML: open in MuseScore, Sibelius, Dorico, Finale
See docs/ for audience-specific guides.
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 Distribution
Built Distribution
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 code_music-5.1.0.tar.gz.
File metadata
- Download URL: code_music-5.1.0.tar.gz
- Upload date:
- Size: 366.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99f913d85b1a80555cc824a682b827e91200d193835d50ed9d3b56c50b78bd1a
|
|
| MD5 |
b7e98e1b98508de63e4c2b91234d49be
|
|
| BLAKE2b-256 |
11bce833a3aba84c7c7dec2f96276e0d3ee9652e3a2078dd9313231c1b580669
|
Provenance
The following attestation bundles were made for code_music-5.1.0.tar.gz:
Publisher:
ci.yml on Talador12/code-music
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
code_music-5.1.0.tar.gz -
Subject digest:
99f913d85b1a80555cc824a682b827e91200d193835d50ed9d3b56c50b78bd1a - Sigstore transparency entry: 1218910704
- Sigstore integration time:
-
Permalink:
Talador12/code-music@5d6119d5c12a2a32c482317c142e9c66b7e4d3dc -
Branch / Tag:
refs/tags/v5.1.0 - Owner: https://github.com/Talador12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@5d6119d5c12a2a32c482317c142e9c66b7e4d3dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file code_music-5.1.0-py3-none-any.whl.
File metadata
- Download URL: code_music-5.1.0-py3-none-any.whl
- Upload date:
- Size: 81.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5c81387165664aeb661c6b779b9b9a782bdba7960d32e984c3fd08355e5947
|
|
| MD5 |
4e391f75740a284d9bdd9617a16d85f1
|
|
| BLAKE2b-256 |
2e8320232346961f95bc6732c7ce81848ce863a307ae3a521d0531bd7cb27413
|
Provenance
The following attestation bundles were made for code_music-5.1.0-py3-none-any.whl:
Publisher:
ci.yml on Talador12/code-music
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
code_music-5.1.0-py3-none-any.whl -
Subject digest:
7c5c81387165664aeb661c6b779b9b9a782bdba7960d32e984c3fd08355e5947 - Sigstore transparency entry: 1218910800
- Sigstore integration time:
-
Permalink:
Talador12/code-music@5d6119d5c12a2a32c482317c142e9c66b7e4d3dc -
Branch / Tag:
refs/tags/v5.1.0 - Owner: https://github.com/Talador12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@5d6119d5c12a2a32c482317c142e9c66b7e4d3dc -
Trigger Event:
push
-
Statement type: