Skip to main content

chordsym

Chord symbols without dependencies (standard library only): is this token a chord, which root and quality, which pitch classes, which key does a song's chord list suggest, and how do the chords read moved by N semitones.

>>> from chordsym import parse_chord, chord_tones, transpose_chord, transposition_table, estimate_key
>>> parse_chord("F#m7"), chord_tones("Cmaj7")
((6, 'minor'), (0, 4, 7, 11))
>>> transpose_chord("C/E", 3, flats=True)
'Eb/G'
>>> transposition_table(["G", "D", "Em", "C"], 3)["chords"]
{'G': 'Bb', 'D': 'F', 'Em': 'Gm', 'C': 'Eb'}

It reads the spellings found in scraped chord charts (C6/9, Bm5-/7, Brazilian 7M, E7(#9), D/F#), not only textbook ones. Pitch classes are ints 0-11 (C = 0).

In the browser: the TypeScript twin

The same functions ship to npm as chordsym (in ts/), with camelCase names and keyword arguments as an options object:

import { parseChord, transposeChord, estimateKey } from "chordsym";

parseChord("Am7");                         // [9, "minor"]
transposeChord("C/E", 3, { flats: true }); // "Eb/G"
estimateKey(["Am", "Dm", "E7"]);           // { tonic: 9, minor: true }

The two are kept identical by construction, not by care:

  • One grammar. Every regular expression and table lives in chordsym/_grammar.py, written in the subset of regex syntax that means the same in Python and JavaScript (no \d, \s, \w, \b). python -m chordsym._codegen writes it to ts/src/grammar.generated.ts, and a test fails if that file is stale.
  • One set of golden cases. fixtures/cases.json holds about 1,500 calls with their expected results, errors included (ValueError in Python is RangeError in TypeScript). pytest and vitest both run every one and compare them as JSON text, so order matters. To add a case, append it and run python -m chordsym._fixtures, which records the Python results; review the diff, since a changed expectation is a behaviour change on both sides.
  • A wide net before releases. python scripts/twin_differential.py (after cd ts && npm run build) runs about 75,000 generated chord spellings and 3,000 songs through both and reports any difference.

Where the languages differ, the TypeScript side says so in its types: transpositionTable(...).chords is a Map (a plain object would reorder integer-like keys), and a Key is a plain { tonic, minor } object checked by every function that takes one (keyEquals compares two).

  • CI runs a slice of that net. python scripts/twin_differential.py --sample-into-fixtures 500 refreshes 2,500 seeded corpus cases inside fixtures/cases.json (tagged "source": "corpus"), next to the hand-written ones.

Traps the port had to handle, worth knowing before writing any Python/TypeScript twin:

  • % keeps the sign of the dividend in JS (-1 % 12 === -1), of the divisor in Python: use a mod helper.
  • A JS object reorders integer-like keys ("2", "10" come first) and treats "__proto__" specially: an ordered mapping is a Map.
  • re.match anchors at the start only; in JS that is a sticky (y) regex whose lastIndex must be reset. re.fullmatch is ^(?:…)$.
  • Python's \d, \s and \w are Unicode-aware and JS's are not, or differ at the edges; str.strip() and String.trim() remove different characters.
  • ^\s+|\s+$ is quadratic in JS on long runs of spaces; trim with an index loop.
  • Python 3.12's sum() compensates float rounding and JS's left-to-right addition does not, so ties can break differently: sum in an explicit loop.
  • Test runners that compare with order-blind equality (dict ==, toStrictEqual) cannot catch an ordering bug: compare JSON text.

Versions: an npm release carries the version of the Python release it was cut from (lockstep at release points, so chordsym@X.Y.Z on npm and PyPI are the same behaviour).

Seeded from songleaf (thorwhalen/songleaf#31). Planned: dialects (Harte, Chordonomicon, Nashville/Roman) as strategies; pychord and music21 as test oracles only.

Metadata

Release files for chordsym 0.0.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 chordsym 0.0.3
File Size Uploaded Provenance Actions
chordsym-0.0.3.tar.gz 51.7 kB Without provenance Details for chordsym-0.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 63.5 kB

Release files / chordsym-0.0.3.tar.gz

Download URL chordsym-0.0.3.tar.gz
Size 51.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ff48c38c6f70a253520ab52d5958122ca81815c18efe2270fcd75bab5dc26ef0
BLAKE2b-256 checksum
How to use checksums
75f2133617407f55947deef09461af3a23eba6cc37140459b3a9b15b9a9aa38d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / chordsym-0.0.3-py3-none-any.whl

Download URL chordsym-0.0.3-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc3cbd645e537017dd2583369260da46ff193e59f32dd1de3b945c5f1bf614c2
BLAKE2b-256 checksum
How to use checksums
dd71131da08a6bf4e909ad3a2ea6417d3a8f9ff6ac956400de06809bca2dd1ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for chordsym 0.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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