Skip to main content

PyChord

PyChord

PyPI Python versions Build Status Documentation Status License: MIT

Overview

PyChord is a pure-Python library for working with musical chords. It parses chord names, lists component notes, transposes chords and progressions, and finds chords from a set of notes.

Installation

PyChord supports Python 3.11 and above.

$ pip install pychord

Basic Usage

Create a chord

>>> from pychord import Chord
>>> c = Chord("Am7")
>>> c
<Chord: Am7>
>>> c = Chord("Am7/G")
>>> c.root, str(c.quality), c.on
('A', 'm7', 'G')

Unknown chord names raise ValueError:

>>> Chord("Cfoo")
Traceback (most recent call last):
  ...
ValueError: Unknown quality: foo

Transpose a chord

>>> c = Chord("Am7/G")
>>> c.transpose(3)
>>> c
<Chord: Cm7/Bb>

Pass a key as the second argument to control whether sharps or flats are used:

>>> c = Chord("C")
>>> c.transpose(1)
>>> c
<Chord: Db>
>>> c = Chord("C")
>>> c.transpose(1, "D")
>>> c
<Chord: C#>

Get component notes

>>> c = Chord("Am7")
>>> c.components()
['A', 'C', 'E', 'G']
>>> c.components_with_pitch(root_pitch=3)
['A3', 'C4', 'E4', 'G4']
>>> c.components(visible=False)  # semitones from C
[9, 12, 16, 19]

Compare chords

>>> Chord("C") == Chord("D")
False
>>> Chord("C#") == Chord("Db")
True

Find chords from notes

>>> from pychord import find_chords_from_notes
>>> find_chords_from_notes(["C", "E", "G"])
[<Chord: C>]
>>> find_chords_from_notes(["F#", "A", "C", "D"])
[<Chord: D7/F#>]
>>> find_chords_from_notes(["F", "G", "C"])
[<Chord: Fsus2>, <Chord: Csus4/F>]

Chord progressions

>>> from pychord import ChordProgression
>>> cp = ChordProgression(["C", "G/B", "Am"])
>>> cp
<ChordProgression: C | G/B | Am>

>>> cp.append("Em/G")
>>> cp
<ChordProgression: C | G/B | Am | Em/G>

>>> cp.transpose(+3)
>>> cp
<ChordProgression: Eb | Bb/D | Cm | Gm/Bb>

>>> cp[1]
<Chord: Bb/D>
>>> len(cp)
4

>>> cp.insert(1, "Fm")
>>> cp.pop()
<Chord: Gm/Bb>
>>> cp + ChordProgression(["Fm", "Bb7"])
<ChordProgression: Eb | Fm | Bb/D | Cm | Fm | Bb7>

Advanced Usage

Create a chord from a scale degree

>>> Chord.from_note_index(note=1, quality="", scale="Cmaj")  # I of C major
<Chord: C>
>>> Chord.from_note_index(note=3, quality="m7", scale="Fmaj")  # IIIm7 of F major
<Chord: Am7>
>>> Chord.from_note_index(note=5, quality="7", scale="Amin")  # V7 of A minor
<Chord: E7>

Supported and custom chord qualities

All built-in qualities are defined in pychord/constants/qualities.py and can be listed with QualityManager().get_qualities().

You can add a new quality or override an existing one. The change applies process-wide to chords created afterwards; call load_default_qualities() to restore the defaults.

>>> from pychord import Chord, QualityManager
>>> Chord("C11").components()
['C', 'E', 'G', 'Bb', 'D', 'F']

>>> quality_manager = QualityManager()
>>> quality_manager.set_quality("11", ("1", "3", "5", "b7", "11"))
>>> Chord("C11").components()
['C', 'E', 'G', 'Bb', 'F']

>>> quality_manager.load_default_qualities()

Inversions

Append /N to a chord name for its Nth inversion. You can also add a bass note after another slash:

>>> Chord("C/1").components() # First inversion of C
['E', 'G', 'C']
>>> Chord("C/2").components() # Second inversion of C
['G', 'C', 'E']

>>> Chord("Cm7/3/F").components() # Third inversion of Cm7 over F
['F', 'Bb', 'C', 'Eb', 'G']

Examples

Development

Development tools are declared as dependency groups in pyproject.toml (requires pip 25.1 or later).

$ pip install -e . --group dev

# Run tests with coverage
$ coverage run -m unittest -v && coverage report

# Lint, format and type check
$ ruff check pychord test examples
$ ruff format --check pychord test examples
$ mypy pychord

# Build the documentation
$ pip install -r docs/requirements.txt
$ make -C docs html

Author

License

  • MIT License

The logo is made from Freepik.

Metadata

Release files for pychord 1.4.3

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

Source distribution (sdist)

Source distribution for pychord 1.4.3
File Size Uploaded Provenance Actions
pychord-1.4.3.tar.gz 20.5 kB With provenance Details for pychord-1.4.3.tar.gz

Built distribution (wheel)

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

Total release size: 35.1 kB

Release files / pychord-1.4.3.tar.gz

Download URL pychord-1.4.3.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7eef3cc02290726b3d46b70fe4124634a33a22a63b6d649353cf03dbe377c9a0
BLAKE2b-256 checksum
How to use checksums
d1354766062c4a5902852945207a8703b007bf65dddd14492614bf0e358c2fc3
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 3, 2026.

Transparency log

Release files / pychord-1.4.3-py3-none-any.whl

Download URL pychord-1.4.3-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35a9ba4ded71e6309acf1d07215d6a1e83529fbb1b0f08d33c15a3d16bd21430
BLAKE2b-256 checksum
How to use checksums
182da17e2aa88ffe8e586cfe9fc12b5271fd3812a5ea9d538552ed9dd31fddc4
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 3, 2026.

Transparency log

Security for pychord 1.4.3

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pychord-1.4.3.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 3, 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.

Release history Release notifications | RSS feed

This release

1.4.3 This release

2 release files Full provenance

0.2.4

0.0.1

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