Skip to main content

songscan

Read songs out of PDFs and images (photos and scans). A chord chart becomes ChordPro, with the song's details (title, artists, key, tempo, time, capo, copyright) alongside; sheet music becomes MusicXML, which songscan can move to another key and draw (and a lead sheet, with chords and lyrics, a ChordPro chart too).

A PDF's own text is read first: charts typed up in a word processor or chart app keep their words and where each sits on the page, so their chords can be put back over the syllables they are played on, without asking anyone. Anything else (scanned PDFs, sheet music, or text that isn't plainly a chord chart) is read by Claude, looking at its pages, as images always are.

Images may be any type Pillow opens. Before Claude sees them they are turned upright (as a phone's photo says to), scaled down to what Claude reads, and sent as JPEG, PNG, GIF or WebP; a multi-page TIFF, as scanners make, as an image a page.

Installation

uv add "songscan @ git+https://github.com/jnhmcknight/songscan.git"

Reading sheet music needs the score extra (music21, verovio and svglib):

uv add "songscan[score] @ git+https://github.com/jnhmcknight/songscan.git"

Reading scans and images needs an Anthropic API key, in ANTHROPIC_API_KEY or a client you pass in. PDFs with their own text don't use it.

Usage

from songscan import ScanError, scan

try:
    result = scan(file_bytes)  # a PDF or an image, told apart by what is in it
except ScanError as error:
    ...  # error.retryable: whether trying again later may work

result.kind       # "chord_chart", "score" or "other"
result.chordpro   # a chord chart's ChordPro, details and all (a lead sheet's too); else None
result.musicxml   # sheet music's MusicXML; else None
result.meta       # ScanMeta: title, artists, key, tempo, time, capo, copyright
result.source     # "text" (the PDF's own) or "vision" (Claude's reading)
result.warnings   # anything to check, or that couldn't be done

To say which it is, scan_pdf(pdf_bytes) or scan_image(image_bytes).

Writing sheet music out can take many minutes (Claude may write it twice, when what it wrote first can't be read). Where a process may only run so long, read it in steps, each of which can run in a process of its own:

from songscan import complete_score, scan, transcribe_score

result = scan(file_bytes, transcribe=False)  # sheet music comes back transcribe_pending
if result.transcribe_pending:
    attempt = transcribe_score(file_bytes)  # one attempt
    if attempt.musicxml is None:
        # attempt.retry is JSON, to keep until the next step
        attempt = transcribe_score(file_bytes, retry=attempt.retry)  # MusicXML, or ScanError
    complete_score(result, attempt.musicxml)  # the details and chart it gives

Sheet music, in another key (by the nearer way up or down, spelled as the key is):

from songscan import score

score.transpose(result.musicxml, "Bb")              # MusicXML
score.render(result.musicxml, "Bb")                 # a page of SVG each
score.render(result.musicxml, "Bb", format="pdf")   # a PDF

Drawing uses the fonts verovio comes with. To use others (or to find them elsewhere), set SONGSCAN_VEROVIO_RESOURCES to their directory, or say where they are each time:

score.render(result.musicxml, "Bb", resources="/path/to/verovio/data")

They are given to each drawing, so it works on any thread: verovio itself only knows where its fonts are on the thread that imported it.

To choose the client or model:

import anthropic

result = scan_pdf(pdf_bytes, client=anthropic.Anthropic(api_key=...), model="claude-opus-5-5")

Development

uv sync
uv run pytest
uv run ruff check && uv run black --check . && uv run pyright

Tests that read PDFs and images with vision use a stand-in for Claude. To run them against the real API instead (which costs a little), set SONGSCAN_LIVE_API=1 with a key in ANTHROPIC_API_KEY:

SONGSCAN_LIVE_API=1 uv run pytest

Tests of how songscan handles the API's answers and errors use the stand-in either way.

Metadata

Release files for songscan 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for songscan 0.4.0
File Size Uploaded Provenance Actions
songscan-0.4.0.tar.gz 18.3 kB Without provenance Details for songscan-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 39.8 kB

Release files / songscan-0.4.0.tar.gz

Download URL songscan-0.4.0.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f60627ea8d5e417a18711c5021adbdd055ba6c117c601832800a83196e80de39
BLAKE2b-256 checksum
How to use checksums
26c9b9708088e33dff913bb2ba11d8ffc35d0a001f99a8edc259053ab11f8e83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / songscan-0.4.0-py3-none-any.whl

Download URL songscan-0.4.0-py3-none-any.whl
Size 21.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
70e3d4f91c744fedc40e9609ed72899c9c97eba5ed117a2967dcf6fccdf04039
BLAKE2b-256 checksum
How to use checksums
8a84ca316c97c5a8798748b7f982fb9a3ba74e7a314993ea83a78c7a38fb0345
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for songscan 0.4.0

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