A Python library for music theory, composition, and audio sketching, letting you analyze chords and scales and render playable MIDI and sound from code.
Rainbow-Dreamer/musicpy
A Python-based music programming language that lets you write, analyze and export music using concise, music-theory-aware syntax and MIDI output.
- Stars
- 1,502
- Forks
- 138
- Open issues
- 0
- Last commit
- 2 months ago
What is it?
Musicpy is a music programming language embedded in Python. It lets you describe notes, chords, melodies, rhythms and volumes with short, readable expressions, and generate musical material from music theory rules and algorithms. Its core data types (note, chord, scale) support arithmetic, so music theory operations can be written in a mathematical style.
The library can export compositions to MIDI files and load existing MIDI files into its data structures for theory-based analysis. It also supports reading and writing MusicXML when the optional partitura dependency is installed, and includes a raw module (musicpy.daw) for lower-level audio work. Playback is available through the play function, which uses pygame.
Installation is via pip on Windows, macOS and Linux, with Python 3.7 or newer. Full documentation and tutorials are hosted on Read the Docs and the project wiki.
Key features
- 01Write notes, chords and melodies with concise, human-readable syntax.
- 02Generate music from music theory rules and algorithms.
- 03Export compositions to MIDI and load MIDI files for analysis.
- 04Supports MusicXML reading and writing via an optional dependency.
- 05Note, chord and scale types support arithmetic operations.
- 06Playback through a built-in play function.
Use cases
- Composing short pieces or chord progressions in code.
- Analyzing the harmony and structure of existing MIDI files.
- Teaching or experimenting with music theory through programming.
- Generating algorithmic or experimental music from rule sets.
Quick start
- 1
Make sure Python 3.7 or newer is installed
- 2
Install musicpy with pip
pip install musicpy - 3
Import musicpy at the start of your file
from musicpy import *
Things to know
- Licensed under LGPL-2.1, so modified library code must stay open under the same terms.
- The play function on Linux needs an older pygame version and the freepats package.
- Some features such as musicxml and the daw module need extra dependencies.
Topics
FAQ
- What is musicpy?
- A Python-based music programming language that lets you write, analyze and export music using concise, music-theory-aware syntax and MIDI output. Musicpy is a music programming language embedded in Python. It lets you describe notes, chords, melodies, rhythms and volumes with short, readable expressions, and generate musical material from music theory rules and algorithms. Its core data types (note, chord, scale) support arithmetic, so music theory operations can be written in a mathematical style.
- Is musicpy free to use? What license does it have?
- musicpy is open source under the LGPL-2.1 license. Check the license terms before using it in commercial products.
- Is musicpy still maintained?
- Updated within 6 months. The last commit to musicpy was on Sep 19, 2026.
- What can I use musicpy for?
- Composing short pieces or chord progressions in code. Analyzing the harmony and structure of existing MIDI files. Teaching or experimenting with music theory through programming. Generating algorithmic or experimental music from rule sets.
- How do I install musicpy?
- Make sure Python 3.7 or newer is installed Install musicpy with pip: pip install musicpy Import musicpy at the start of your file: from musicpy import *
- Where can I get musicpy?
- The source code and installation instructions are on GitHub: https://github.com/Rainbow-Dreamer/musicpy
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Free, open-source DJ software for performing live mixes on Linux, Windows and macOS.
A free, open-source singing synthesis editor for UTAU users, supporting UTAU voicebanks, phonemizers, and plugins on Windows, macOS, and Linux.
Self-hostable, web-based guitar and bass tab viewer and player with audio sync, similar to Songsterr.
Local, offline desktop studio for macOS and Windows that turns text into speech, clones voices, and generates songs with lyrics and MIDI scores.
An experimental pattern-based DAW where one pattern can be edited in a tracker, piano roll or step grid, with CLAP and VST3 plugin support.