pymusicxml package

A simple utility for exporting MusicXML files that represents musical objects more hierarchically.

While it is of course possible to create MusicXML files in Python directly via ElementTree, the format is awkwardly non-hierarchical. For instance, there are no separate objects for chords and tuplets; rather they exist only as special annotations to the note objects themselves. In pymusicxml, chords are represented similarly to notes but with multiple pitches, and tuplets are treated as containers for notes, chords, and rests.

At the moment, this library is intended as a tool for composition, making it easier to construct and export MusicXML scores in Python. In the future, the ability to parse existing MusicXML scores may be added.



Module containing all of the classes representing musical objects.

Public-Facing API (result of import *):

BarRest(bar_length, …)

Class representing a bar rest.


Special duration object used for bar rests.

BeamedGroup(*args, **kwds)

Represents a group of notes/chords/rests joined under a single beam.

Chord(pitches, str]], duration, str, float], …)

Class representing a chord.

Clef(sign, line, octaves_transposition)

Class representing a musical clef

Duration(note_type, num_dots, tuplet_ratio)

Represents a length that can be written as a single note or rest.

EndDashedLine([id_number, voice, staff])

Class used to mark the end of a dashed line starting from a TextAnnotation.

GraceChord(pitches, str]], duration, str, …)

Subclass of Chord representing a durationless grace chord.

GraceNote(pitch, str], duration, str, …[, …])

Subclass of Note representing a durationless grace note.

Measure(*args, **kwds)

Class representing a measure of music, perhaps with multiple voices.

MetronomeMark(beat_length, bpm, voice, …)

Class representing a tempo-specifying metronome mark

Note(pitch, str], duration, str, float], ties)

Class representing a single, pitched note.

Notehead(notehead_name, filled)

Class representing a notehead type.

Part(*args, **kwds)

Represents a musical part/staff.

PartGroup(*args, **kwds)

Represents a part group (a group of related parts, possible connected by a bracket)

Pitch(step, octave, alteration)

Class representing a notated musical pitch.

Rest(duration, str, float], notations, str, …)

Class representing a notated rest.

Score(*args, **kwds)

Class representing a full musical score


Notation to attach to a note that starts a glissando


Multi-gliss notation used for glissing multiple members of a chord


Notation to attach to a note that starts a slur


Notation to attach to a note that ends a glissando


End of a multi-gliss notation used for glissing multiple members of a chord.


Notation to attach to a note that ends a slur

TextAnnotation(text, placement, font_size, …)

Class representing text that is attached to the staff

Tuplet(*args, **kwds)

Represents a tuplet; same as a BeamedGroup, but with a particular time ratio associated with it.