playscan
Python client for the PlayScan API: send photos or PDFs of
printed sheet music, get back MusicXML, compressed MusicXML (.mxl) or MIDI.
Install
pip install playscan
Requires Python 3.9+. The only dependency is requests.
Quickstart
Get a key at developer.playscan.app (new accounts get 10 free
pages once, no card), then:
from playscan import PlayScan
result = PlayScan(api_key="ps_live_...").scan("page1.jpg")
print(result.save()) # score.musicxml
If you leave out api_key, the client reads PLAYSCAN_API_KEY from the environment. Keep the key on
the server: the API does not accept browser (CORS) requests.
More options:
client = PlayScan() # PLAYSCAN_API_KEY
# Several images = several pages of one score, in order.
result = client.scan(["p1.jpg", "p2.jpg"], format="midi")
result.save("song.mid")
# A PDF, only pages 2-4, with progress output.
result = client.scan(
"book.pdf",
format="mxl",
page_range=(2, 4),
on_progress=lambda s: print(s.status, s.progress),
)
print(result.charged_pages, "pages charged,", result.balance_pages, "left")
files can be a path, bytes, a binary file object, or a list of them.
Command line
export PLAYSCAN_API_KEY=ps_live_...
playscan scan page1.jpg page2.jpg -f midi -o song.mid
playscan scan book.pdf --pages 1-3 # saves score.musicxml
playscan balance # pages left
Progress goes to stderr, the saved path to stdout. On an API error the command prints
error <code>: <message> and exits with code 1.
API
| Method |
What it does |
scan(files, format="musicxml", page_range=None, poll_interval=2.0, wait_timeout=600, on_progress=None) |
Create a scan, wait, download. Returns a Result. |
create_scan(files, page_range=None) |
Upload and start a scan. Returns Scan(id, status, pages, deduplicated). |
get_scan(id) |
Returns ScanStatus(id, status, progress, pages, charged_pages, error, queue_position, eta_seconds). |
wait(id, poll_interval=2.0, wait_timeout=600, on_progress=None) |
Poll until done. Returns the final ScanStatus. |
download(id, format="musicxml") |
Result bytes. format: musicxml, mxl, midi or zip. Free and repeatable. |
cancel(id) |
Cancel a scan that is still queued. |
balance() |
Pages left on the account. |
Result has content, format, filename, scan_id, charged_pages, balance_pages and
save(path=None), which writes the file (by default to filename in the current directory; a directory
path gets filename inside it, missing folders are created) and returns the path.
Constructor: PlayScan(api_key=None, *, base_url="https://api.playscan.app", timeout=120, max_retries=5).
base_url can also come from PLAYSCAN_BASE_URL.
Uploading the same files with the same options again returns the existing scan
(deduplicated=True) and is not charged again.
Errors
API errors and wait errors are playscan.PlayScanError with status, code, message, retry_after and
body. Invalid arguments (for example an unknown format or a bad page_range) raise ValueError or
TypeError, and a file path that cannot be read raises OSError.
ScanFailedError: the scan ended as failed or canceled. code is the scan's error code (for
example no_staff_lines) or canceled; scan_id is attached.
ScanTimeoutError: wait_timeout passed. The scan keeps running on the server; call wait(e.scan_id)
again later.
Common codes: unauthorized (401), insufficient_balance (402), not_found (404),
unsupported_file / too_many_pages / upload_too_large (422), too_many_active (429),
result_expired (410). The client retries rate_limited (429) and busy (503) on its own, waiting the
Retry-After time, up to max_retries times. It does not retry too_many_active.
Limits
- JPEG, PNG or TIFF images, or exactly one PDF; up to 30 pages per scan.
- 30 MB per file, 60 MB per upload.
- 2 active scans per account; 10 new scans and 120 requests per minute.
- Results can be downloaded for 24 hours. Uploaded images are deleted after 24 hours and are not used to
train models.
- Printed music only, not handwriting. Recognition is automatic and can make mistakes; check the result.
Pricing
Pay per page with one-time packs, no subscription, pages never expire: $10 / 100, $40 / 600,
$125 / 2,500, $350 / 10,000 pages. Only pages that were read are charged; failed pages go back to your
balance.
Links
License
MIT