Skip to content

ChordType

chord_type

The chord type dictionary — 106 chord definitions.

The ChordType namespace exposes an in-memory dictionary of 106 chord types, each indexed by:

  • Full name (e.g. "major seventh")
  • Aliases (e.g. "maj7", "Δ", "M7")
  • Set number (a decimal int 0-4095)
  • Chroma string (12-bit binary)

So ChordType.get("maj7"), ChordType.get("Δ"), ChordType.get(2193), and ChordType.get("100010010001") all return the same ChordType.

The dictionary is mutable: add extends it, remove_all clears it. Useful for project-specific chord vocabularies.

Example

from tonal_py import ChordType len(ChordType.all()) 106 ChordType.get("maj7").intervals ('1P', '3M', '5P', '7M') ChordType.get("maj7").quality 'Major'

Source parity: @tonaljs/chord-type

get

get(type_: Any) -> ChordType

Look up a chord type by name, alias, set number, or chroma string.

Parameters:

Name Type Description Default
type_ Any

A lookup key. May be a full name, alias, integer set number, or 12-bit chroma string.

required

Returns:

Type Description
ChordType

A ChordType dataclass. Returns NO_CHORD_TYPE for unknown input.

Example

from tonal_py import ChordType ChordType.get("maj7").intervals ('1P', '3M', '5P', '7M') ChordType.get("M7").intervals # alias resolves to same chord ('1P', '3M', '5P', '7M') ChordType.get("nonexistent").empty True

Source code in src/tonal_py/chord_type.py
def get(type_: Any) -> ChordType:
    """Look up a chord type by name, alias, set number, or chroma string.

    Args:
        type_: A lookup key. May be a full name, alias, integer set number,
            or 12-bit chroma string.

    Returns:
        A `ChordType` dataclass. Returns `NO_CHORD_TYPE` for unknown input.

    Example:
        >>> from tonal_py import ChordType
        >>> ChordType.get("maj7").intervals
        ('1P', '3M', '5P', '7M')
        >>> ChordType.get("M7").intervals       # alias resolves to same chord
        ('1P', '3M', '5P', '7M')
        >>> ChordType.get("nonexistent").empty
        True
    """
    return _INDEX.get(type_, NO_CHORD_TYPE)

names

names() -> list[str]

Get the full names of every named chord type.

Filters out entries that have only aliases (no full name set).

Example

from tonal_py import ChordType "major seventh" in ChordType.names() True

Source code in src/tonal_py/chord_type.py
def names() -> list[str]:
    """Get the full names of every named chord type.

    Filters out entries that have only aliases (no full name set).

    Example:
        >>> from tonal_py import ChordType
        >>> "major seventh" in ChordType.names()
        True
    """
    return [c.name for c in _DICTIONARY if c.name]

symbols

symbols() -> list[str]

Get the primary symbol (first alias) of every chord type with one.

Example

from tonal_py import ChordType "maj7" in ChordType.symbols() True

Source code in src/tonal_py/chord_type.py
def symbols() -> list[str]:
    """Get the primary symbol (first alias) of every chord type with one.

    Example:
        >>> from tonal_py import ChordType
        >>> "maj7" in ChordType.symbols()
        True
    """
    return [c.aliases[0] for c in _DICTIONARY if c.aliases]

keys

keys() -> list[Any]

Return every key in the lookup index (names, aliases, set nums, chromas).

Useful for debugging or sanity-checking the dictionary.

Source code in src/tonal_py/chord_type.py
def keys() -> list[Any]:
    """Return every key in the lookup index (names, aliases, set nums, chromas).

    Useful for debugging or sanity-checking the dictionary.
    """
    return list(_INDEX.keys())

all

all() -> list[ChordType]

Return all 106 chord types as a fresh list.

Example

from tonal_py import ChordType len(ChordType.all()) 106

Source code in src/tonal_py/chord_type.py
def all() -> list[ChordType]:  # noqa: A001
    """Return all 106 chord types as a fresh list.

    Example:
        >>> from tonal_py import ChordType
        >>> len(ChordType.all())
        106
    """
    return _DICTIONARY.copy()

remove_all

remove_all() -> None

Clear the entire chord dictionary.

After calling this, all get lookups return NO_CHORD_TYPE until add is called or _seed() repopulates from the original CHORDS table. Useful when defining a project-specific custom vocabulary.

Mutates module-level state

This affects everything that uses ChordType lookups, including Chord.get. Tests that mutate should restore via _seed().

Source code in src/tonal_py/chord_type.py
def remove_all() -> None:
    """Clear the entire chord dictionary.

    After calling this, all `get` lookups return `NO_CHORD_TYPE` until
    `add` is called or `_seed()` repopulates from the original `CHORDS`
    table. Useful when defining a project-specific custom vocabulary.

    !!! warning "Mutates module-level state"
        This affects everything that uses `ChordType` lookups, including
        `Chord.get`. Tests that mutate should restore via `_seed()`.
    """
    _DICTIONARY.clear()
    _INDEX.clear()

add

add(intervals: list[str], aliases: list[str], full_name: str | None = None) -> None

Add a chord type to the dictionary.

The new chord is indexed by its full name (if provided), set number, chroma, and every alias.

Parameters:

Name Type Description Default
intervals list[str]

List of interval names (e.g. ["1P", "3M", "5P"]).

required
aliases list[str]

Symbol aliases (e.g. ["test", "tst"]).

required
full_name str | None

Optional canonical full name.

None
Example

from tonal_py import ChordType ChordType.add(["1P", "3M", "5P", "7M"], ["mytest"], "test major7") ChordType.get("mytest").quality 'Major'

Cleanup so doctest doesn't leave state behind

ChordType.remove_all() from tonal_py.chord_type import _seed _seed()

Source code in src/tonal_py/chord_type.py
def add(intervals: list[str], aliases: list[str], full_name: str | None = None) -> None:
    """Add a chord type to the dictionary.

    The new chord is indexed by its full name (if provided), set number,
    chroma, and every alias.

    Args:
        intervals: List of interval names (e.g. `["1P", "3M", "5P"]`).
        aliases: Symbol aliases (e.g. `["test", "tst"]`).
        full_name: Optional canonical full name.

    Example:
        >>> from tonal_py import ChordType
        >>> ChordType.add(["1P", "3M", "5P", "7M"], ["mytest"], "test major7")
        >>> ChordType.get("mytest").quality
        'Major'
        >>> # Cleanup so doctest doesn't leave state behind
        >>> ChordType.remove_all()
        >>> from tonal_py.chord_type import _seed
        >>> _seed()
    """
    quality = _get_quality(intervals)
    pcset_data = _pcset.get(intervals)
    chord = ChordType(
        empty=False,
        name=full_name or "",
        set_num=pcset_data.set_num,
        chroma=pcset_data.chroma,
        normalized=pcset_data.normalized,
        intervals=tuple(intervals),
        quality=quality,
        aliases=tuple(aliases),
    )
    _DICTIONARY.append(chord)
    if chord.name:
        _INDEX[chord.name] = chord
    _INDEX[chord.set_num] = chord
    _INDEX[chord.chroma] = chord
    for alias in chord.aliases:
        add_alias(chord, alias)

add_alias

add_alias(chord: ChordType, alias: str) -> None

Index chord under an additional alias.

Parameters:

Name Type Description Default
chord ChordType

An existing ChordType.

required
alias str

A new alias string to register.

required
Source code in src/tonal_py/chord_type.py
def add_alias(chord: ChordType, alias: str) -> None:
    """Index `chord` under an additional alias.

    Args:
        chord: An existing `ChordType`.
        alias: A new alias string to register.
    """
    _INDEX[alias] = chord