lytk
lytk reads and writes symbolic music, and turns it into training data.
Scores in LilyPond, MusicXML, MIDI, ABC and Humdrum **kern go through one
internal representation, so any format converts to any other. The same scores
come out as NumPy note arrays, piano rolls and event sequences, ready for
PyTorch or TensorFlow. The core is written in Rust; you use it from Python or
from the command line.
Preview release (0.x). Conversion, transforms and the ML pipeline are tested and ready to use. The API can still change before 1.0: notation marks (articulations, ornaments, dynamics) will move from strings to enums.
Why lytk
- LilyPond is a first-class format. lytk reads real LilyPond files, not a
subset: variables,
\relative, piano scores with several voices per staff, repeats and voltas, cadenzas, lyrics, chord names and figured bass. It writes them back out too, in any of LilyPond's 12 note-name languages. - Conversions are measured, not assumed. Every round trip (LilyPond,
MusicXML, ABC,
**kern, MIDI) is checked in CI against a test corpus for note counts, pitches, onsets and durations. The results can only improve from one release to the next. - Built for machine learning. Encoders for note arrays, piano rolls and Performance-RNN event sequences, objective metrics from the muspy family, folder datasets with deterministic splits and caching, and padded data loaders for PyTorch and TensorFlow.
- Fast. A Rust core with prebuilt wheels, and a batch converter that uses every core. It transposes LilyPond about 50× faster than python-ly.
Install
pip install lytk # every format, transform and representation
pip install "lytk[torch]" # + PyTorch datasets and data loaders
pip install "lytk[tensorflow]" # + tf.data datasets and data loaders
pip install "lytk[eval]" # + generation-evaluation metrics (scipy, FMD)
pip install "lytk[all]" # everything above
Wheels are prebuilt for Linux, macOS and Windows and cover CPython 3.10 and newer, so no Rust toolchain is needed. PyTorch and TensorFlow are optional and only imported when you ask for a loader.
Quick start
import lytk
score = lytk.from_musicxml("input.xml") # or from_lilypond, from_midi, from_abc, from_humdrum
score = lytk.transpose(score, semitones=3) # also invert, retrograde, change_language
lytk.to_lilypond(score, "output.ly") # or to_musicxml, to_midi, to_abc, to_humdrum
abc = lytk.to_abc(score) # without a path, writers return the text
Turn a score into arrays:
doc = score.to_music_document()
notes = lytk.to_note_array(doc) # (N, 4): onset, duration, pitch, velocity
roll = lytk.to_piano_roll(doc) # (T, 128)
events = lytk.to_event_sequence(doc) # Performance-RNN event codes
stats = lytk.compute_metrics(doc) # pitch-class entropy, polyphony, scale consistency, …
Each encoder has an inverse (from_note_array, …). The arrays are ordinary
NumPy arrays, and NumPy supports DLPack,
so PyTorch, JAX and CuPy can use them without copying:
import torch
tensor = torch.from_dlpack(lytk.to_piano_roll(doc)) # shares the buffer
Build a dataset from a folder of scores in any mix of formats:
from lytk.datasets import FolderDataset
data = FolderDataset("corpus/", cache_dir=".cache")
train, val, test = data.split((0.8, 0.1, 0.1), seed=0)
loader = train.to_pytorch_dataloader("event_sequence", batch_size=32, shuffle=True)
for events, lengths in loader: # padded batch plus each item's true length
...
Scores differ in length, so each batch is padded. The true lengths come back
alongside it because 0 is a valid event, pitch and velocity, so padding alone
can't tell you where a score ends. to_tensorflow_dataloader works the same way.
The package also installs a lytk command:
lytk convert input.xml -o output.ly # formats are taken from the extensions
lytk convert corpus/ -o out/ -f xml -j 8 # a whole folder, in parallel
lytk transpose input.ly -s 3 -o up.ly
lytk flatten score.ly -o flat.ly # inline every \include
lytk info input.mxl
It also inverts, reverses, changes note-name languages, compares scores
(lytk diff) and runs JSON batch jobs; lytk --help lists every command and
docs/cli.md describes them.
Formats
| Format | Extensions | Read | Write |
|---|---|---|---|
| LilyPond | .ly .ily |
✓ | ✓ |
| MusicXML | .xml .musicxml |
✓ | ✓ |
| Compressed MusicXML | .mxl |
✓ | ✓ |
| MIDI | .mid .midi |
✓ | ✓ |
| ABC | .abc |
✓ | ✓ |
Humdrum **kern |
.krn |
✓ | ✓ |
docs/import-export.md lists what each reader and writer keeps. MusicXML is the most complete; MIDI keeps no slurs, articulations or lyrics.
Not there yet
- Tablature, percussion (unpitched notes) and fretboard diagrams.
- MIDI import transcribes the file as it is. It does not yet quantize, separate voices, detect tuplets or split the hands of a piano part.
- Non-traditional key signatures, cross-staff notes (
\change Staff), and Humdrum spine splits (*^,*v). Files that use spine splits are rejected with an error. - The ABC and
**kernwriters produce one stream per staff, so two voices sharing a staff are not kept separate. - MEI is planned after 1.0.
Documentation
- Command line
- What each format reads and writes
- Design and internals
- Building from source and running the tests
- Changelog and roadmap
Contributing
Issues and pull requests are welcome. See CONTRIBUTING.md, and SECURITY.md for reporting vulnerabilities.
Acknowledgements
lytk builds on a lot of prior work in music notation software. Its LilyPond
parser uses the
tree-sitter-lilypond
grammar by Nathan Whetsell (MIT, notice in
src/tree-sitter/LICENSE). Its design also owes a
lot to LilyPond,
python-ly,
music21,
muspy,
abjad,
symusic and
MuseScore.
License
MIT, see LICENSE. The test fixtures are third-party scores under their own terms (tests/fixtures/README.md).
Release files for lytk 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lytk-0.1.0.tar.gz | 702.0 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| lytk-0.1.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| lytk-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| lytk-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| lytk-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| lytk-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| lytk-0.1.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| lytk-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 23.3 MB
Release files / lytk-0.1.0.tar.gz
| Download URL | lytk-0.1.0.tar.gz |
|---|---|
| Size | 702.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5127f94a66a8898affa3b3230f69bb10678711dc0b0f8dcb9ebb92253d0d1efa
|
|
BLAKE2b-256 checksum How to use checksums |
c520cb0268bebee01d5047021cdbf6101098d8ed3af715ce1cd98e5aac1de422
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | lytk-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2ba565b4ec8b0b2b2696fb51b3739f7a340ab48d986b88d368d4dbc36cc3a8a6
|
|
BLAKE2b-256 checksum How to use checksums |
dc3745aaeef751f913bdd5f3106691ad12a74d897ba6b9bbfa3de170c12d6b5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | lytk-0.1.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 3.6 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
2e5682d50f19c650a62f08e2a8790183dd6f7f10d78aa5f9b351542d556f22fd
|
|
BLAKE2b-256 checksum How to use checksums |
6a919aca0902cac2d93cc13c4000fa4fafc454a71f50ef0b9377483a9df5db75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | lytk-0.1.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 3.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
ccea9c047d48e0177f9158fab21f8ffb03004a81c10bdd2fefb2c184477e0ddc
|
|
BLAKE2b-256 checksum How to use checksums |
fb4750b805a57c8ce1ce176742fb5d88b0a3a80f0fecde2800b259bd3bfd8bd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | lytk-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7101ccb0252ce8dc1ed6f4bb67ca5f0df187776e99a28e5d71dfb224e81cc506
|
|
BLAKE2b-256 checksum How to use checksums |
4228b6be09752775f57f90882b01fbb953d9ded46e05389f7d41bf6285a9e6b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | lytk-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6c3f9f1da8d703e669f6e688a3b5b5736041ba342f53e1d7be10f550d89f6586
|
|
BLAKE2b-256 checksum How to use checksums |
187670e0037d879a51acd40ad950f2572fc8eb8fc47ee55b3e7c12392334bdbc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | lytk-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b38a33dd109fd20d7c2b3d13f07284983d4bad9358ce996c660dd14fadf96cf1
|
|
BLAKE2b-256 checksum How to use checksums |
8d12335d441e0005ac78ea506f5023f898356cd93f7c6da7c81efd2308eb1c10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency logRelease files / lytk-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | lytk-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5bd7a1e7b0b3040196fefb2f8b41fa4fddc40b8c748a7bf591e15345caa22f29
|
|
BLAKE2b-256 checksum How to use checksums |
d71cd7f55f1cf85e3462ef1feeccf1a1ac7467189f19b1bca91f66f4a9b48866
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.
Transparency log