pychord package

Subpackages

Submodules

pychord.analyzer module

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

Find possible chords consisted from notes

Parameters:

notes – List of note arranged from lower note. ex) [“C”, “Eb”, “G”]

Returns:

List of chord

pychord.analyzer.get_all_rotated_notes(notes: List[str]) List[List[str]][source]

Get all rotated notes

get_all_rotated_notes([A,C,E]) -> [[A,C,E],[C,E,A],[E,A,C]]

pychord.analyzer.notes_to_positions(notes: List[str], root: str) List[int][source]

Get notes positions from the root note

>>> notes_to_positions(["C", "E", "G"], "C")
[0, 4, 7]
Parameters:
  • notes – List of notes

  • root – Root note

Returns:

List of note positions

pychord.chord module

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

Bases: object

Class to handle a chord.

Attributes:

_chord: Name of the chord. (e.g. C, Am7, F#m7-5/A) _root: The root note of chord. (e.g. C, A, F#) _quality: The quality of chord. (e.g. maj, m7, m7-5) _appended: The appended notes on chord. _on: The base note of slash chord.

property appended

The appended notes on chord

property chord

The name of chord

components(visible: bool = True) List[str] | List[int][source]

Return the component notes of chord

Parameters:

visible – returns the name of notes if True else list of int

Returns:

component notes of chord

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

Returns:

component notes of chord

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

Create a Chord from 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-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 :param quality)

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

info()[source]

Return information of chord to display

property on

The base note of slash chord

property quality

The quality of chord

property root

The root note of chord

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

Transpose the chord

Parameters:
  • trans – Transpose key

  • scale – key scale

pychord.parser module

pychord.parser.parse(chord: str) Tuple[str, Quality, List[str], str][source]

Parse a string to get chord component

Parameters:

chord – str expression of a chord

Returns:

(root, quality, appended, on)

pychord.progression module

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

Bases: object

Class to handle chord progressions.

Attributes:

_chords: component chords of chord progression.

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

Append a chord to chord progressions

Parameters:

chord – A chord to append

property chords: List[Chord]

Get component chords of chord progression

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

Insert a chord to chord progressions

Parameters:
  • index – Index to insert a chord

  • chord – A chord to insert

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

Pop a chord from chord progressions

Parameters:

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

transpose(trans: int) None[source]

Transpose whole chord progressions

Parameters:

trans – Transpose key

pychord.quality module

class pychord.quality.Quality(name: str, components: Tuple[int, ...])[source]

Bases: object

Chord quality

append_on_chord(on_chord, root)[source]

Append on chord

To create Am7/G q = Quality(‘m7’) q.append_on_chord(‘G’, root=’A’)

Parameters:
  • on_chord (str) – bass note of the chord

  • root (str) – root note of the chord

get_components(root='C', visible=False)[source]

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 quality

Get name of quality

class pychord.quality.QualityManager(*args, **kwargs)[source]

Bases: object

Singleton class to manage the qualities

find_quality_from_components(components: List[int])[source]

Find a quality from components

Parameters:

components – components of quality

get_qualities()[source]
get_quality(name: str, inversion: int = 0) Quality[source]
load_default_qualities()[source]
set_quality(name: str, components: Tuple[int, ...])[source]

Set a Quality

This method will not affect any existing Chord instances. :param name: name of quality :param components: components of quality

pychord.utils module

pychord.utils.display_appended(appended: List[str]) str[source]
pychord.utils.display_on(on_note: str) str[source]
pychord.utils.note_to_val(note: str) int[source]

Get index value of a note

>>> note_to_val("C")
0
>>> note_to_val("B")
11
pychord.utils.transpose_note(note: str, transpose: int, scale: str = 'C') str[source]

Transpose a note

>>> transpose_note("C", 1)
"Db"
>>> transpose_note("D", 4, "A")
"F#"
pychord.utils.val_to_note(val: int, scale: str = 'C', index: int | None = None, quality: str | None = None) str[source]

Return note by index in a scale

>>> val_to_note(0)
"C"
>>> val_to_note(11, "D")
"D#"

Module contents