Skip to main content

Latest Release Pypi Package Unittest Status CodeCov Status Contributor Covenant

Partitura is a Python package for handling symbolic musical information. It supports loading from and exporting to MusicXML and MIDI files. It also supports loading from Humdrum kern and MEI.

The full documentation for partitura is available online at readthedocs.org.

User Installation

The easiest way to install the package is via pip from the PyPI (Python Package Index):

pip install partitura

This will install the latest release of the package and will install all dependencies automatically.

Quickstart

A detailed tutorial with some hands-on MIR applications is available here.

The following code loads the contents of an example MusicXML file included in the package:

import partitura as pt
my_xml_file = pt.EXAMPLE_MUSICXML
score = pt.load_score(my_xml_file)

The partitura load_score function will import any score format, i.e. (Musicxml, Kern, MIDI or MEI) to a partitura.Score object. The score object will contain all the information in the score, including the score parts. The following shows the contents of the first part of the score:

part = score.parts[0]
print(part.pretty())

Output:

Part id="P1" name="Piano"
 │
 ├─ TimePoint t=0 quarter=12
 │   │
 │   └─ starting objects
 │       │
 │       ├─ 0--48 Measure number=1
 │       ├─ 0--48 Note id=n01 voice=1 staff=2 type=whole pitch=A4
 │       ├─ 0--48 Page number=1
 │       ├─ 0--24 Rest id=r01 voice=2 staff=1 type=half
 │       ├─ 0--48 System number=1
 │       └─ 0-- TimeSignature 4/4
 │
 ├─ TimePoint t=24 quarter=12
 │   │
 │   ├─ ending objects
 │   │   │
 │   │   └─ 0--24 Rest id=r01 voice=2 staff=1 type=half
 │   │
 │   └─ starting objects
 │       │
 │       ├─ 24--48 Note id=n02 voice=2 staff=1 type=half pitch=C5
 │       └─ 24--48 Note id=n03 voice=2 staff=1 type=half pitch=E5
 │
 └─ TimePoint t=48 quarter=12
     │
     └─ ending objects
         │
         ├─ 0--48 Measure number=1
         ├─ 0--48 Note id=n01 voice=1 staff=2 type=whole pitch=A4
         ├─ 24--48 Note id=n02 voice=2 staff=1 type=half pitch=C5
         ├─ 24--48 Note id=n03 voice=2 staff=1 type=half pitch=E5
         ├─ 0--48 Page number=1
         └─ 0--48 System number=1
  

If lilypond or MuseScore are installed on the system, the following command renders the part to an image and displays it:

pt.render(part)

Score example

The notes in this part can be accessed through the property part.notes:

part.notes
> [<partitura.score.Note object at 0x...>, <partitura.score.Note object at 0x...>, 
> <partitura.score.Note object at 0x...>]

The following code stores the start, end, and midi pitch of the notes in a numpy array:

import numpy as np
pianoroll = np.array([(n.start.t, n.end.t, n.midi_pitch) for n in part.notes])
print(pianoroll)
> [[ 0 48 69]
>  [24 48 72]
>  [24 48 76]]

The note start and end times are in the units specified by the divisions element of the MusicXML file. This element specifies the duration of a quarter note. The divisions value can vary within an MusicXML file, so it is generally better to work with musical time in beats.

The part object has a property :part.beat_map that converts timeline times into beat times:

beat_map = part.beat_map
print(beat_map(pianoroll[:, 0]))
> [0. 2. 2.]
print(beat_map(pianoroll[:, 1]))
> [4. 4. 4.]

The following commands save the part to MIDI and MusicXML, or export it as a WAV file (using additive synthesis), respectively:

# Save Score MIDI to file.
pt.save_score_midi(part, 'mypart.mid')

# Save Score MusicXML to file.
pt.save_musicxml(part, 'mypart.musicxml')

# Save as audio file using additive synthesis
pt.save_wav(part, 'mypart.wav')

More elaborate examples can be found in the documentation <https://partitura.readthedocs.io/en/latest/index.html>_.

Import other formats

For MusicXML files do:

import partitura as pt
my_xml_file = pt.EXAMPLE_MUSICXML
score = pt.load_musicxml(my_xml_file)

For Kern files do:

import partitura as pt
my_kern_file = pt.EXAMPLE_KERN
score = pt.load_kern(my_kern_file)

For MEI files do:

import partitura as pt
my_mei_file = pt.EXAMPLE_MEI
score = pt.load_mei(my_mei_file)

One can also import any of the above formats by just using:

import partitura as pt
any_score_format_path = pt.EXAMPLE_MUSICXML
score = pt.load_score(any_score_format_path)

License

The code in this package is licensed under the Apache 2.0 License. For details, please see the LICENSE file.

Citing Partitura

If you find Partitura useful, we would appreciate if you could cite us!

@inproceedings{partitura_mec,
  title={{Partitura: A Python Package for Symbolic Music Processing}},
  author={Cancino-Chac\'{o}n, Carlos Eduardo and Peter, Silvan David and Karystinaios, Emmanouil and Foscarin, Francesco and Grachten, Maarten and Widmer, Gerhard},
  booktitle={{Proceedings of the Music Encoding Conference (MEC2022)}},
  address={Halifax, Canada},
  year={2022}
}

Acknowledgments

This project receives funding from the European Research Council (ERC) under the European Union's Horizon 2020 research and innovation programme under grant agreement No 101019375 "Whither Music?".

This work has received support from the European Research Council (ERC) under the European Union’s Horizon 2020 research and innovation programme under grant agreement No. 670035 project "Con Espressione" and the Austrian Science Fund (FWF) under grant P 29840-G26 (project "Computer-assisted Analysis of Herbert von Karajan's Musical Conducting Style")

Metadata

Release files for partitura 1.9.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 partitura 1.9.0
File Size Uploaded Provenance Actions
partitura-1.9.0.tar.gz 404.7 kB Without provenance Details for partitura-1.9.0.tar.gz

Built distribution (wheel)

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

Total release size: 768.6 kB

Release files / partitura-1.9.0.tar.gz

Download URL partitura-1.9.0.tar.gz
Size 404.7 kB
Tags Source
SHA-256 checksum
How to use checksums
feb1042de1bbdeee8ebae8440cd3655596b0c01df2c4a7ae174a00349049df9d
BLAKE2b-256 checksum
How to use checksums
912fc8dbdfe2192a8930fd8c0d33398c5567adebe053ae556306e1626b5b9e26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / partitura-1.9.0-py3-none-any.whl

Download URL partitura-1.9.0-py3-none-any.whl
Size 363.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7e7f73259379dc73d38b31db558763b6c3b59256b189268889fbac90ec5e0d0
BLAKE2b-256 checksum
How to use checksums
c66285f327f02c0558c458f6d00ea661b3f22305a836d6dbfc92044f002117c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for partitura 1.9.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