Functions, field=None, corpusNames=None, fileExtensions=None)

Search all stored metadata bundles and return a list of file paths.

The names parameter can be used to specify which corpora to search, for example:

...     'bach',
...     corpusNames=('core', 'virtual'),
...     )
<music21.metadata.bundles.MetadataBundle {150 entries}>

If names is None, all corpora known to music21 will be searched.

This method uses stored metadata and thus, on first usage, will incur a performance penalty during metadata loading.


class music21.corpus.corpora.Corpus

Abstract base class of all corpora subclasses.

Corpus read-only properties


Returns a tuple of DirectoryInformation objects for a each directory in self._directoryInformation.

>>> core = corpus.corpora.CoreCorpus()
>>> diBrief = core.directoryInformation[0:4]
>>> diBrief
(<music21.corpus.corpora.DirectoryInformation airdsAirs>,
 <music21.corpus.corpora.DirectoryInformation bach>, 
 <music21.corpus.corpora.DirectoryInformation beethoven>, 
 <music21.corpus.corpora.DirectoryInformation ciconia>)
>>> diBrief[3].directoryTitle
'Johannes Ciconia'

The metadata bundle for a corpus:

>>> from music21 import corpus
>>> corpus.corpora.CoreCorpus().metadataBundle
<music21.metadata.bundles.MetadataBundle 'core': {144... entries}>

The name of a given corpus.

Corpus methods

static Corpus.fromName(name)

Instantiate a specific corpus based on name:

TODO: Down with staticmethods!!!

>>> corpus.corpora.Corpus.fromName('core')
>>> corpus.corpora.Corpus.fromName('virtual')
>>> corpus.corpora.Corpus.fromName('local')
<music21.corpus.corpora.LocalCorpus: 'local'>
>>> corpus.corpora.Corpus.fromName('test')
<music21.corpus.corpora.LocalCorpus: 'test'>

The paths of the files in a given corpus.

static Corpus.listSearchFields()

List all available search field names:

TODO: remove from Corpus and make a function.

>>> for field in corpus.corpora.Corpus.listSearchFields():
...     field
static Corpus.parse(workName, movementNumber=None, number=None, fileExtensions=None, forceSource=False, format=None)

# TODO: Remove from static method – make a function for the module.

The most important method call for corpus.

Similar to the parse() method of converter (which takes in a filepath on the local hard drive), this method searches the corpus (including the virtual corpus) for a work fitting the workName description and returns a

If movementNumber is defined, and a movement is included in the corpus, that movement will be returned.

If number is defined, and the work is a collection with multiple components, that work number will be returned. For instance, some of our ABC documents contain dozens of folk songs within a single file.

Advanced: if forceSource is True, the original file will always be loaded freshly and pickled (e.g., pre-parsed) files will be ignored. This should not be needed if the file has been changed, since the filetime of the file and the filetime of the pickled version are compared. But it might be needed if the music21 parsing routine has changed.

Example, get a chorale by Bach. Note that the source type does not need to be specified, nor does the name Bach even (since it’s the only piece with the title BWV 66.6)

>>> from music21 import corpus
>>> bachChorale = corpus.corpora.Corpus.parse('bwv66.6')
>>> len(

After parsing, the file path within the corpus is stored as .corpusFilePath

>>> bachChorale.corpusFilepath
'bach/bwv66.6.mxl', field=None, fileExtensions=None)

Search the corpus.


Update a corpus’ metadata bundle from its stored JSON file on disk.


class music21.corpus.corpora.CoreCorpus

A model of the core corpus.

>>> coreCorpus = corpus.corpora.CoreCorpus()

CoreCorpus bases

CoreCorpus read-only properties

Return True or False if this is a corpus or noCoprus distribution.

>>> from music21 import corpus
>>> corpus.corpora.CoreCorpus().noCorpus

Read-only properties inherited from Corpus:

CoreCorpus read/write properties


Set music21’s core corpus to a directory, and save that information in the user settings.

This is specifically for use with “no corpus” music21 packages, where the core corpus was not included with the rest of the package functionality, and had to be installed separately.

Set it to a directory:

>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> coreCorpus.manualCoreCorpusPath = '~/Desktop'

Unset it:

>>> coreCorpus.manualCoreCorpusPath = None
>>> coreCorpus.manualCoreCorpusPath is None

CoreCorpus methods


Return the file name of all Bach chorales.

By default, only Bach Chorales in xml format are returned, because the quality of the encoding and our parsing of those is superior.

N.B. Look at the module corpus.chorales for many better ways to work with the chorales.

>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> a = coreCorpus.getBachChorales()
>>> len(a) > 400
>>> a = coreCorpus.getBachChorales('krn')
>>> len(a) > 10
>>> a = coreCorpus.getBachChorales('xml')
>>> len(a) > 400
>>> a[0]
CoreCorpus.getComposer(composerName, fileExtensions=None)

Return all filenames in the corpus that match a composer’s or a collection’s name. An fileExtensions, if provided, defines which extensions are returned. An fileExtensions of None (default) returns all extensions.

Note that xml and mxl are treated equivalently.

>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> a = coreCorpus.getComposer('bach')
>>> len(a) > 100
>>> a = coreCorpus.getComposer('bach', 'krn')
>>> len(a) < 10
>>> a = coreCorpus.getComposer('bach', 'xml')
>>> len(a) > 10

Given the name of a composer, get the path to the top-level directory of that composer:

>>> import os
>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> a = coreCorpus.getComposerDirectoryPath('ciconia')
>>> a.endswith(os.path.join('corpus', os.sep, 'ciconia'))
>>> a = coreCorpus.getComposerDirectoryPath('bach')
>>> a.endswith(os.path.join('corpus', os.sep, 'bach'))
>>> a = coreCorpus.getComposerDirectoryPath('handel')
>>> a.endswith(os.path.join('corpus', os.sep, 'handel'))

Return a list of the filenames of all Monteverdi madrigals.

>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> a = coreCorpus.getMonteverdiMadrigals()
>>> len(a) > 40
CoreCorpus.getPaths(fileExtensions=None, expandExtensions=True)

Get all paths in the core corpus that match a known extension, or an extenion provided by an argument.

If expandExtensions is True, a format for an extension, and related extensions, will replaced by all known input extensions.

This is convenient when an input format might match for multiple extensions.

>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()
>>> corpusFilePaths = coreCorpus.getPaths()
>>> 2500 < len(corpusFilePaths) < 2600
>>> kernFilePaths = coreCorpus.getPaths('krn')
>>> len(kernFilePaths) >= 500
>>> abcFilePaths = coreCorpus.getPaths('abc')
>>> len(abcFilePaths) >= 100
CoreCorpus.getWorkList(workName, movementNumber=None, fileExtensions=None)

Search the corpus and return a list of filenames of works, always in a list.

If no matches are found, an empty list is returned.

>>> from music21 import corpus
>>> coreCorpus = corpus.corpora.CoreCorpus()

# returns 1 even though there is a ‘.mus’ file, which cannot be read...

>>> len(coreCorpus.getWorkList('cpebach/h186'))
>>> len(coreCorpus.getWorkList('cpebach/h186', None, '.xml'))
>>> len(coreCorpus.getWorkList('schumann_clara/opus17', 3))
>>> len(coreCorpus.getWorkList('schumann_clara/opus17', 2))

Make sure that ‘verdi’ just gets the single Verdi piece and not the Monteverdi pieces:

>>> len(coreCorpus.getWorkList('verdi'))
1, field=None, fileExtensions=None)

Search the core corpus for metadata entries:

>>> corpus.corpora.CoreCorpus().search('3/4')
<music21.metadata.bundles.MetadataBundle {1866 entries}>
>>> corpus.corpora.CoreCorpus().search(
...      'bach',
...      field='composer',
...      )
<music21.metadata.bundles.MetadataBundle {21 entries}>
>>> predicate = lambda noteCount: noteCount < 20
>>> corpus.corpora.CoreCorpus().search(
...     predicate,
...     field='noteCount',
...     )
<music21.metadata.bundles.MetadataBundle {132 entries}>

Methods inherited from Corpus:


class music21.corpus.corpora.LocalCorpus(name=None)

A model of a local corpus.

>>> localCorpus = corpus.corpora.LocalCorpus()

The default local corpus is unnamed, but an arbitrary number of independent, named local corpora can be defined and persisted:

>>> namedLocalCorpus = corpus.corpora.LocalCorpus('with a name')

LocalCorpus bases

LocalCorpus read-only properties


The directory paths in use by a given local corpus.


True if this local corpus has a corresponding entry in music21’s user settings, otherwise false.

The name of a given local corpus.

>>> from music21 import corpus
>>> corpus.corpora.LocalCorpus().name
>>> corpus.corpora.LocalCorpus(name='Bach Chorales').name
'Bach Chorales'

Read-only properties inherited from Corpus:

LocalCorpus methods


Add a directory path to a local corpus:

>>> localCorpus = corpus.corpora.LocalCorpus('a new corpus')
>>> localCorpus.addPath('~/Desktop')

Paths added in this way will not be persisted from session to session unless explicitly saved by a call to


Delete a non-default local corpus from the user settings.

LocalCorpus.getPaths(fileExtensions=None, expandExtensions=True)

Access files in additional directories supplied by the user and defined in environment settings in the ‘localCorpusSettings’ list.

If additional paths are added on a per-session basis with the addPath() function, these paths are also returned with this method.

static LocalCorpus.listLocalCorporaNames()

List the names of all user-defined local corpora.

The entry for None refers to the default local corpus.


Remove a directory path from a local corpus.

If that path is included in the list of persisted paths for the given corpus, it will be removed permanently.

Save the current list of directory paths in use by a given corpus in the user settings., field=None, fileExtensions=None)

Search a local corpus.

See for examples, as the interface is the same.

Methods inherited from Corpus:


class music21.corpus.corpora.VirtualCorpus

A model of the virtual corpus. that stays online...

>>> virtualCorpus = corpus.corpora.VirtualCorpus()

VirtualCorpus bases

VirtualCorpus read-only properties

The name of the virtual corpus:

>>> corpus.corpora.VirtualCorpus().name

Read-only properties inherited from Corpus:

VirtualCorpus methods

VirtualCorpus.getPaths(fileExtensions=None, expandExtensions=True)

Get all paths in the virtual corpus that match a known extension.

An extension of None will return all known extensions.

>>> len(corpus.corpora.VirtualCorpus().getPaths()) > 6
VirtualCorpus.getWorkList(workName, movementNumber=None, fileExtensions=None)

Given a work name, search all virtual works and return a list of URLs for any matches.

>>> virtualCorpus = corpus.corpora.VirtualCorpus()
>>> virtualCorpus.getWorkList('bach/bwv1007/prelude')
>>> virtualCorpus.getWorkList('junk')
[], field=None, fileExtensions=None)

Search the virtual corpus.

See for examples, as the interface is the same.

Methods inherited from Corpus:


class music21.corpus.corpora.CorpusFile(path, title, filename, format, ext)

CorpusFile read-only properties


Alias for field number 4


Alias for field number 2


Alias for field number 3


Alias for field number 0


Alias for field number 1


class music21.corpus.corpora.CorpusWork(title, files, virtual)

CorpusWork read-only properties


Alias for field number 1


Alias for field number 0


Alias for field number 2


class music21.corpus.corpora.DirectoryInformation(dirName='', dirTitle='', isComposer=True, corpusObject=None)

returns information about a directory in a Corpus. Called from

only tested with CoreCorpus so far.

DirectoryInformation methods


populate other information about the directory such as files and filenames.

>>> di = corpus.corpora.DirectoryInformation('schoenberg')
>>> di.findWorks()
OrderedDict([(...'opus19', CorpusWork(title='Opus 19', 
                                                 title='Movement 2', 
                                                 title='Movement 6', 


class music21.corpus.corpora.VirtualCorpusFile(path, title, url, format)

VirtualCorpusFile read-only properties


Alias for field number 3


Alias for field number 0


Alias for field number 1


Alias for field number 2