kennethreitz.org / Software / Pytheory

PyTheory: Music Theory for Humans

pytheory is a Python library that simplifies working with music theory concepts. It provides a simple and intuitive interface for representing musical elements such as notes, scales, chords, and intervals, making it easier to work with music theory in Python.

Features

This project is highly experimental, and is more of a thought exercise than a practical library. It aims to explore how music theory concepts can be represented and manipulated using Python, and to provide a foundation for further research and development in this area.

Installation

You can install pytheory using pip:

$ pip install pytheory

Usage

Create a Note object:

>>> import pytheory

>>> c_minor = TonedScale(tonic='C4')['minor']
>>> c_minor
<Scale I=C4 II=D4 III=Eb4 IV=F4 V=G4 VI=Ab4 VII=Bb5 VIII=C5>

>>> c_minor[0].pitch()
523.251130601197

>>> c_minor["I"].pitch(symbolic=True)
440*2**(1/4)

>>> c_minor["tonic"].pitch(temperament='pythagorean', symbolic=True)
14080/27

I'm not sure if this is useful, but it's fun to play with, and it has enhanced my understanding of music theory— especially the symbolic parameter.