Skip to main content

ChordPro file format parser and renderer

Project description

ChordSketch

chordsketch

ChordSketch Python bindings — parse and render ChordPro files from Python via native Rust extensions generated by UniFFI.

Native extension — no pure-Python fallback. The library compiles to a platform wheel; prebuilt wheels for common platforms are published to PyPI so no Rust toolchain is needed to install.

Installation

pip install chordsketch

Requires Python 3.8+ (CPython or PyPy).

Quick Start

import chordsketch

source = """{title: Amazing Grace}
{key: G}

[G]Amazing [G7]grace, how [C]sweet the [G]sound"""

html = chordsketch.parse_and_render_html(source)
text = chordsketch.parse_and_render_text(source)
pdf  = chordsketch.parse_and_render_pdf(source)   # bytes

print(chordsketch.version())

API

Rendering

All render functions accept the same three arguments:

Parameter Type Description
input str ChordPro source text
config_json str | None Preset name ("guitar", "ukulele") or inline RRJSON; None for defaults
transpose int | None Semitone offset (-128..127); None defaults to 0
Function Returns Description
parse_and_render_text(input, config_json, transpose) str Plain text output
parse_and_render_html(input, config_json, transpose) str Full HTML document
parse_and_render_pdf(input, config_json, transpose) bytes Raw PDF bytes
parse_and_render_text_with_warnings(input, config_json, transpose) TextRenderWithWarnings { output: str, warnings: list[str] } Plain text + captured warnings
parse_and_render_html_with_warnings(input, config_json, transpose) TextRenderWithWarnings { output: str, warnings: list[str] } HTML + captured warnings
parse_and_render_pdf_with_warnings(input, config_json, transpose) PdfRenderWithWarnings { output: bytes, warnings: list[str] } PDF + captured warnings

The *_with_warnings variants return the render warnings (transpose saturation, chorus recall limits, {columns} clamp, etc.) as a list alongside the output instead of forwarding them to sys.stderr / NSLog / System.err / $stderr. Use them when embedding ChordSketch in an app that needs to surface warnings in the UI or aggregate them. See #1827.

Validation

errors = chordsketch.validate(source)  # list[ValidationError] — empty if clean
for e in errors:
    print(f"line {e.line}, column {e.column}: {e.message}")

Utility

print(chordsketch.version())  # e.g. "0.2.0"

Options

# Transpose up 2 semitones with the ukulele preset
html = chordsketch.parse_and_render_html(source, "ukulele", 2)

# Inline RRJSON configuration
html = chordsketch.parse_and_render_html(
    source,
    '{"settings": {"notation": "solfege"}}',
    None,
)

Error handling

Functions raise chordsketch.ChordSketchError on invalid configuration:

try:
    html = chordsketch.parse_and_render_html(source, "{ bad json !!!", None)
except chordsketch.ChordSketchError as e:
    print(e)

ChordSketchError has two variants:

  • NoSongsFound — the input produced no parseable songs (rare with lenient parsing)
  • InvalidConfig — the config_json argument is not a known preset and not valid RRJSON

Parse errors in the ChordPro input are not raised — the renderer is lenient and produces a best-effort result. Call validate() to surface diagnostics.

Links

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chordsketch-0.3.0.tar.gz (5.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

chordsketch-0.3.0-py3-none-win_amd64.whl (6.0 MB view details)

Uploaded Python 3Windows x86-64

chordsketch-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

chordsketch-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

chordsketch-0.3.0-py3-none-macosx_11_0_arm64.whl (6.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

chordsketch-0.3.0-py3-none-macosx_10_12_x86_64.whl (6.1 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file chordsketch-0.3.0.tar.gz.

File metadata

  • Download URL: chordsketch-0.3.0.tar.gz
  • Upload date:
  • Size: 5.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for chordsketch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1d5bed3b74c43379f300485bbfe7668288fb88ecf2711c6e553ab6834d0a296d
MD5 f4315b457922a760987e05c1dbee35a7
BLAKE2b-256 1ab796448a195e6d3f10cfa540ac4e49f03ef260012fe71250157aaaa7faca4c

See more details on using hashes here.

File details

Details for the file chordsketch-0.3.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for chordsketch-0.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 2d351b0b15d4073b8378165428eae50b470b83d25f2ee588c455523a4aa956d8
MD5 a0b8e6c83eb08ad90f4b1f5b32dedf61
BLAKE2b-256 bd198313f1f6e66c4332c7bf985e939e67777f10ef932496f8573e63123d1398

See more details on using hashes here.

File details

Details for the file chordsketch-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for chordsketch-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6de46f9c6f6973b983ca89443dac0c0a4e007e95574d9bba6de81dd82a1a3b7d
MD5 39b33926e6797c5fdc000ef250c422a0
BLAKE2b-256 21cefcec3e6151f85c709be96239890460a4fbd192913ebf9753aea80802296a

See more details on using hashes here.

File details

Details for the file chordsketch-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for chordsketch-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0ae349bd1d9563f69f098440ea7bb103e8c5e092fa1d99ea601ac26f79182f4e
MD5 d5659fc3f42aa93fc22c915e4696253b
BLAKE2b-256 6792fdbe2e0153ea6c9fbda09a0d0cd1f603e59ee9a9f249fc7bd595da58389e

See more details on using hashes here.

File details

Details for the file chordsketch-0.3.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for chordsketch-0.3.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 12a82dc7195bd962ee88ed45058eafebfb9156b87517ff547bd4014f7c3f1f5f
MD5 9044f6057c1bd141fc3992b7c440b258
BLAKE2b-256 b2df47dcb4ef62b7eb7c17690000e62017abb12112138086e9a79dd1235756b1

See more details on using hashes here.

File details

Details for the file chordsketch-0.3.0-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for chordsketch-0.3.0-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 694cdfd63e85f56161ba8be1800e6491251146c817d3a49c6c9e45c2cd80a7d6
MD5 bea488a57b42b2529bd827d420b1b86f
BLAKE2b-256 abc5a7d08e3c5e8d9f49175fb524c4b628595dbd9355dea5ad31abd250f075e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page