pychord package

class pychord.Chord(chord: str)[source]

A chord, made up of two or more notes.

Parameters:

chord – Name of the chord, e.g. "C", "Am7", "F#m7-5/A".

property chord: str

The name of the chord, e.g. "C", "Am7", "F#m7-5/A".

components(visible: Literal[True]) list[str][source]
components(visible: Literal[False]) list[int]

Return the component notes of the chord.

Parameters:

visible – Returns the note names if True, the note pitches otherwise.

components_with_pitch(root_pitch: int) list[str][source]

Return the component notes of chord formatted like ["C4", "E4", "G4"].

Parameters:

root_pitch – The pitch of the root note.

classmethod from_note_index(note: int, quality: str, scale: str, diatonic: bool = False, chromatic: int = 0) Chord[source]

Create a Chord from a note index in a scale.

  • Chord.from_note_index(1, "", "Cmaj") returns I of C major => Chord(“C”)

  • Chord.from_note_index(3, "m7", "Fmaj") returns IIImin of F major => Chord(“Am7”)

  • Chord.from_note_index(5, "7", "Amin") returns Vmin of A minor => Chord(“E7”)

  • Chord.from_note_index(2, "", "Cmaj") returns II of C major => Chord(“D”)

  • Chord.from_note_index(2, "m", "Cmaj") returns IImin of C major => Chord(“Dm”)

  • Chord.from_note_index(2, "", "Cmaj", diatonic=True) returns IImin of C major => Chord(“Dm”)

  • Chord.from_note_index(2, "", "Cmin", chromatic=-1) returns bII of C minor => Chord(“Db”)

Parameters:
  • note – Scale degree of the chord’s root, 1 to 7.

  • quality – Quality of the chord, e.g. "m7", "sus4".

  • scale – Base scale, e.g. "Cmaj", "Amin", "F#maj", "Ebmin".

  • diatonic – If True, chord quality is determined using the base scale (overrides quality).

  • chromatic – Lower or raise the scale degree (and all notes of the chord) by semitone(s).

info() str[source]

Return information of chord to display.

property on: str

The bass note of a slash chord.

property quality: Quality

The quality of the chord, e.g. "maj", "m7", "m7-5".

property root: str

The root note of the chord, e.g. "C", "A", "F#".

transpose(trans: int, scale: str = 'C') None[source]

Transpose the chord.

Parameters:
  • trans – The number of semitones.

  • scale – Key scale.

class pychord.ChordProgression(initial_chords: str | Chord | list[str] | list[Chord] = [])[source]

A chord progression, which is a sequence of Chord instances.

Parameters:

initial_chords – Initial chord or chords of the chord progression.

append(chord: str | Chord) None[source]

Append a chord to the chord progression.

Parameters:

chord – A chord to append.

property chords: list[Chord]

The component chords of the chord progression.

insert(index: int, chord: str | Chord) None[source]

Insert a chord into the chord progression.

Parameters:
  • index – Index to insert a chord.

  • chord – A chord to insert.

pop(index: int = -1) Chord[source]

Pop a chord from the chord progression.

Parameters:

index – Index of the chord to pop (default: -1).

transpose(trans: int) None[source]

Transpose the whole chord progression.

Parameters:

trans – The number of semitones.

class pychord.Quality(name: str, intervals: tuple[str, ...])[source]

A chord quality, defined by its intervals.

You should never need to create instances of this class yourself.

Use QualityManager if you need to define a new quality or override an existing one.

Parameters:
  • name – Name of the quality.

  • intervals – Intervals defining the quality.

get_components(root: str, visible: Literal[True]) list[str][source]
get_components(root: str, visible: Literal[False]) list[int]
get_components(root: str, visible: bool) list[str] | list[int]

Get components of chord quality

Parameters:
  • root (str) – the root note of the chord

  • visible (bool) – returns the name of notes if True

Return type:

list[str|int]

Returns:

components of chord quality

property intervals: list[str]

The intervals definining the quality, e.g. ["1", "3", "5"] or ["1", "b3", "5", "b7"].

property quality: str

The name of the quality, e.g. "maj", "m7".

class pychord.QualityManager[source]

Singleton class to manage the chord qualities.

find_quality_from_components(components: list[int]) Quality | None[source]

Find a quality from its components.

Parameters:

components – Components of the quality.

set_quality(name: str, intervals: tuple[str, ...]) None[source]

Define a new quality or override an existing one.

This method will not affect any existing Chord instances.

Parameters:
  • name – Name of the quality, e.g. "m".

  • intervals – Intervals defining the quality, e.g. ["1", "b3", "5"].

pychord.find_chords_from_notes(notes: list[str]) list[Chord][source]

Find possible chords consisting of the given notes.

Parameters:

notes – List of notes arranged from lower note, e.g. ["C", "Eb", "G"].