Skip to main content

musicxml is a python library for creating musicxml files. It is largely based on xsd definitions of MusicXML 4.0.

musicxml is also a part of library: musicscore. Feel free to check out under: https://github.com/alexgorji/musicscore & https://musicscore.readthedocs.io

INSTALLATION

  1. Check the version of python on your computer: python --version. This library requires Python 3.11 or later. Possibly you have to install this version (for example via Homebrew or whatever way you choose.)

  2. Make a new folder and create a virtual environment for your project and install musicxml via pip:

    • mkdir
    • cd
    • python3 -m venv venv
    • source venv/bin/activate
    • pip install --upgrade pip
    • pip install musicxml

The SOURCECODE can be found on Github: https://github.com/alexgorji/musicxml

Each musicxml element can be created as an instance of a class which behaves (hopefully exactly!) as the musicxml schema (version 4, see musicxml_4_0.xsd in musicxml.generate_classes) specifies, e.g.:

pitch = XMLPitch()

Children can be added with method add_child():

pitch.add_child(XMLStep('G'))

As a shortcut it is possible to add, remove or change child with a dot operator:

pitch.xml_step = 'G'

is equivalent to:

pitch.xml_step = XMLStep('G')

change:

pitch.xml_step = 'F'

or remove:

pitch.xml_step = None

Dot operator can also be used as a shortcut to get a child:

print(pitch.xml_step.value)

The value of an element (which be translated to text of xml element) can be set during or after creation:

octave = pitch.add_child(XMLOctave())
octave.value = 3

Attributes also can be added during or after creation:

font = XMLFont(font_family='Arial')
font.font_size = 17.2

A variety of errors are thrown during creating an object (for example if you try to add a child of a wrong type or to add a wrong attribute) . The method to_string() calls an intern final check before exporting the xml element to a string to be sure you didn't forget any required children and attributes.

An existing musicxml file can be parsed easily with parser's parse_musicxml(file_path) function.

Each element creates a rather complicated tree format container with xsd indicator objects (XSDSequence, XSDChoice, XSDGroup, XSDElement) which represent their counterparts in a xsd structure to validate and order its children (take a peek inside the file musicxml_4_0.xsd in musicxml.generate_classes to get a feeling for its complexity). If a child is going to be added to an element it tries to 'hook' this child inside a XSDElement leaf of this container tree which has the same name as the child. For elements which use a choice indicator (XSDChoice) it can happen, that the current chosen path throws an error since this particular path does not have a XSDElement leaf with child's name, or it could for example require another not existing child in the final check. It these cases the parent element tries to attach its children to another choice path and see if the problem can be solved. On this account although some thorough testings have been done, there is yet no guaranty that in some cases the library does not behave as it should. Please let me know if you discover a bug!

Metadata

Release files for musicxml 1.6.3

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

Source distribution (sdist)

Source distribution for musicxml 1.6.3
File Size Uploaded Provenance
musicxml-1.6.3.tar.gz 873.0 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 1.9 MB

Release files / musicxml-1.6.3.tar.gz

Download URL musicxml-1.6.3.tar.gz
Size 873.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ead1ab039429dd67666c6f7a416ef009fa3a168bbfab98cdf400b581c311cf90
BLAKE2b-256 checksum
How to use checksums
25301897db717f3103e4d8af0bba4752f94859fa53ff5ffac0631c81f25f95ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.5 Darwin/23.6.0

Release files / musicxml-1.6.3-py3-none-any.whl

Download URL musicxml-1.6.3-py3-none-any.whl
Size 978.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6a66e591b4219c51d6a27f69759f0531aaa952eea1b337bc5247970d6d84819
BLAKE2b-256 checksum
How to use checksums
8b29070cb56c294c8e40622ecddfe31ad7d936456cc61271d26f83fb8879f4f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.5 Darwin/23.6.0

Security for musicxml 1.6.3

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