# Python music libraries

Python music libraries read, write, and analyze music as notes, scores, or audio. A symbolic library treats music as notes and durations rather than as the sampled sound waves that an audio library processes. These libraries let music apps, research tools, and AI models compose, transcribe, and analyze songs in code.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Mido](#mido) | 1.4M | 1.7K | Oct 2024 | MIT |
| [Pedalboard](#pedalboard) | 1.1M | 6.5K | Oct 2026 | GPL-3.0 |
| [music21](#music) | 972.5K | 2.6K | Oct 2026 | BSD-3-Clause |
| [pretty_midi](#pretty-midi) | 690.8K | 1.0K | Jul 2026 | MIT |
| [Symusic](#symusic) | 463.8K | 190 | Apr 2026 | MIT |
| [Basic Pitch](#basic-pitch) | 396.1K | 6.1K | Aug 2024 | Apache-2.0 |
| [python-rtmidi](#python-rtmidi) | 207.1K | 417 | Nov 2023 | MIT |
| [Essentia](#essentia) | 116.3K | 3.8K | May 2026 | AGPL-3.0-only |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Mido](#mido) has the most monthly downloads in this comparison, at 1.4M.

## Capabilities

| Library | Read MIDI event model | Write MIDI files | Live MIDI ports |
| --- | --- | --- | --- |
| [Mido](#mido) | Yes | Yes | Via plugin |
| [Pedalboard](#pedalboard) | No | No | No |
| [music21](#music) | Yes | Yes | No |
| [pretty_midi](#pretty-midi) | Yes | Yes | No |
| [Symusic](#symusic) | Yes | Yes | No |
| [Basic Pitch](#basic-pitch) | No | Yes | No |
| [python-rtmidi](#python-rtmidi) | No | No | Yes |
| [Essentia](#essentia) | No | No | No |

## Libraries

### Mido

[GitHub](https://github.com/mido/mido) · [PyPI](https://pypi.org/project/mido) · [Docs](https://pypi.org/project/mido/)

Provides MIDI message objects, file handling, and APIs for MIDI ports.

- Downloads / mo: 1.4M
- Stars: 1.7K
- Last release: 1.3.3
- License: MIT
- Capabilities: [From the Mido docs](https://pypi.org/project/mido/)

**Strengths**

- **Edits individual MIDI messages.** Read, change, and save messages within MIDI tracks.
- **Connects to live MIDI ports.** Use input and output ports through the selected backend.

**Watch out for**

- **Hardware ports need a backend.** Install a supported backend before opening physical MIDI ports.
- **Track times use delta ticks.** Convert absolute event positions into delta ticks when building MIDI tracks.

```sh
python -m pip install mido
```

**craffel/pretty-midi** (1.0K stars)

[craffel/pretty-midi](https://github.com/craffel/pretty-midi) 

```python
def write(self, filename, round_tempo=False):
    """Write the MIDI data out to a .mid file.

    Parameters
    ----------
    filename : str or file
        Path or file to write .mid file to.
    round_tempo : bool
        If True, round MIDI tempos to the nearest integer microsecond per
        quarter note. If False, truncate them for backwards compatibility.
        Default is False.

    """

    def event_compare(event1, event2):
        """Compares two events for sorting.

        Events are sorted by tick time ascending. Events with the same tick
        time ares sorted by event type. Some events are sorted by
        additional values. For example, Note On events are sorted by pitch
        then velocity, ensuring that a Note Off (Note On with velocity 0)
        will never follow a Note On with the same pitch.

        Parameters
        ----------
        event1, event2 : mido.Message
           Two events to be compared.
        """
        # Construct a dictionary which will map event names to numeric
        # values which produce the correct sorting.  Each dictionary value
        # is a function which accepts an event and returns a score.
        # The spacing for these scores is 256, which is larger than the
        # largest value a MIDI value can take.
        secondary_sort = {
            'set_tempo': lambda e: (1 * 256 * 256),
            'time_signature': lambda e: (2 * 256 * 256),
            'key_signature': lambda e: (3 * 256 * 256),
            'lyrics': lambda e: (4 * 256 * 256),
            'text_events' :lambda e: (5 * 256 * 256),
            'program_change': lambda e: (6 * 256 * 256),
            'pitchwheel': lambda e: ((7 * 256 * 256) + e.pitch),
            'control_change': lambda e: (
                (8 * 256 * 256) + (e.control * 256) + e.value),
            'note_off': lambda e: ((9 * 256 * 256) + (e.note * 256)),
            'note_on': lambda e: (
                (10 * 256 * 256) + (e.note * 256) + e.velocity),
            'end_of_track': lambda e: (11 * 256 * 256)
        }
        # If the events have the same tick, and both events have types
        # which appear in the secondary_sort dictionary, use the dictionary
        # to determine their ordering.
        if (event1.time == event2.time and
                event1.type in secondary_sort and
                event2.type in secondary_sort):
            return (secondary_sort[event1.type](event1) -
                    secondary_sort[event2.type](event2))
        # Otherwise, just return the difference of their ticks.
        return event1.time - event2.time

    # Initialize output MIDI object
    mid = mido.MidiFile(ticks_per_beat=self.resolution, charset=self._charset)
    # Create track 0 with timing information
    timing_track = mido.MidiTrack()
    # Add a default time signature only if there is not one at time 0.
    add_ts = True
    if self.time_signature_changes:
        add_ts = min([ts.time for ts in self.time_signature_changes]) > 0.0
    if add_ts:
        # Add time signature event with default values (4/4)
        timing_track.append(mido.MetaMessage(
            'time_signature', time=0, numerator=4, denominator=4))

    # Add in each tempo change event
    for (tick, tick_scale) in self._tick_scales:
        # Convert seconds per tick to microseconds per quarter note
        tempo = (mido.bpm2tempo(60./(tick_scale*self.resolution))
                 if round_tempo else int(6e7/(60./(tick_scale*self.resolution))))
        timing_track.append(mido.MetaMessage(
            'set_tempo', time=tick, tempo=tempo))
    # Add in each time signature
    for ts in self.time_signature_changes:
        timing_track.append(mido.MetaMessage(
            'time_signature', time=self.time_to_tick(ts.time),
            numerator=ts.numerator, denominator=ts.denominator))
    # Add in each key signature
    # Mido accepts key changes in a different format than pretty_midi, this
    # list maps key number to mido key name
    key_number_to_mido_key_name = [
        'C', 'Db', 'D', 'Eb', 'E', 'F', 'F#', 'G', 'Ab', 'A', 'Bb', 'B',
        'Cm', 'C#m', 'Dm', 'D#m', 'Em', 'Fm', 'F#m', 'Gm', 'G#m', 'Am',
        'Bbm', 'Bm']
    for ks in self.key_signature_changes:
        timing_track.append(mido.MetaMessage(
            'key_signature', time=self.time_to_tick(ks.time),
            key=key_number_to_mido_key_name[ks.key_number]))
    # Add in all lyrics events
    for l in self.lyrics:
        timing_track.append(mido.MetaMessage(
            'lyrics', time=self.time_to_tick(l.time), text=l.text))
    # Add text events
    for l in self.text_events:
        timing_track.append(mido.MetaMessage(
            'text', time=self.time_to_tick(l.time), text=l.text))
    # Sort the (absolute-tick-timed) events.
    timing_track.sort(key=functools.cmp_to_key(event_compare))
    # Add in an end of track event
    timing_track.append(mido.MetaMessage(
        'end_of_track', time=timing_track[-1].time + 1))
    mid.tracks.append(timing_track)
    # Create a list of possible channels to assign - this seems to matter
    # for some synths.
    channels = list(range(16))
    # Don't assign the drum channel by mistake!
    channels.remove(9)
    for n, instrument in enumerate(self.instruments):
        # Initialize track for this instrument
        track = mido.MidiTrack()
        # Add track name event if instrument has a name
        if instrument.name:
            track.append(mido.MetaMessage(
                'track_name', time=0, name=instrument.name))
        # If it's a drum event, we need to set channel to 9
        if instrument.is_drum:
            channel = 9
        # Otherwise, choose a channel from the possible channel list
        else:
            channel = channels[n % len(channels)]
        # Set the program number
        track.append(mido.Message(
            'program_change', time=0, program=instrument.program,
            channel=channel))
        # Add all note events
        for note in instrument.notes:
            # Construct the note-on event
            track.append(mido.Message(
                'note_on', time=self.time_to_tick(note.start),
                channel=channel, note=note.pitch, velocity=note.velocity))
            # Also need a note-off event (note on with velocity 0)
            track.append(mido.Message(
                'note_on', time=self.time_to_tick(note.end),
                channel=channel, note=note.pitch, velocity=0))
        # Add all pitch bend events
        for bend in instrument.pitch_bends:
            track.append(mido.Message(
                'pitchwheel', time=self.time_to_tick(bend.time),
                channel=channel, pitch=bend.pitch))
        # Add all control change events
        for control_change in instrument.control_changes:
            track.append(mido.Message(
                'control_change',
                time=self.time_to_tick(control_change.time),
                channel=channel, control=control_change.number,
                value=control_change.value))
        # Sort all the events using the event_compare comparator.
        track = sorted(track, key=functools.cmp_to_key(event_compare))

        # If there's a note off event and a note on event with the same
        # tick and pitch, put the note off event first
        for n, (event1, event2) in enumerate(zip(track[:-1], track[1:])):
            if (event1.time == event2.time and
                    event1.type == 'note_on' and
                    event2.type == 'note_on' and
                    event1.note == event2.note and
                    event1.velocity != 0 and
                    event2.velocity == 0):
                track[n] = event2
                track[n + 1] = event1
        # Finally, add in an end of track event
        track.append(mido.MetaMessage(
            'end_of_track', time=track[-1].time + 1))
        # Add to the list of output tracks
        mid.tracks.append(track)
    # Turn ticks to relative time from absolute
    for track in mid.tracks:
        tick = 0
        for event in track:
            event.time -= tick
            tick += event.time
    # Write it out
    if isinstance(filename, six.string_types) or isinstance(filename, pathlib.PurePath):
        # If a string or path was given, pass it as the filename
        mid.save(filename=filename)
    else:
        # Otherwise, try passing it in as a file pointer
        mid.save(file=filename)
```

[pretty_midi/pretty_midi.py](https://github.com/craffel/pretty-midi/blob/0df351ff2949ef80e788343e952fe15e473f0cde/pretty_midi/pretty_midi.py#L1398-L1582) · [More projects using Mido →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20mido%20for%20MIDI%20serialization%2C%20score%20parsing%20and%20note-event%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import mido
message = mido.Message('note_on', note=60, velocity=64)
print(message)

```

From [midi.html](https://mido.readthedocs.io/en/stable/messages/)

### Pedalboard

[GitHub](https://github.com/spotify/pedalboard) · [PyPI](https://pypi.org/project/pedalboard) · [Docs](https://pypi.org/project/pedalboard/)

Adds effects to audio.

- Downloads / mo: 1.1M
- Stars: 6.5K
- Last release: 0.9.26
- License: GPL-3.0
- Capabilities: [From the Pedalboard docs](https://pypi.org/project/pedalboard/)

```sh
python -m pip install pedalboard mido
```

**Quickstart**

```python
from pedalboard import load_plugin
from mido import Message
instrument = load_plugin('your-instrument.vst3')
audio = instrument(
    [Message('note_on', note=60), Message('note_off', note=60, time=5)],
    duration=5, sample_rate=44100,
)
print(audio.shape)

```

From [examples.rst](https://spotify.github.io/pedalboard/examples.html) · [Find projects using Pedalboard →](https://dashboard.exa.ai/playground/search?q=pedalboard%20GitHub%20projects)

### music21

[GitHub](https://github.com/cuthbertLab/music21) · [PyPI](https://pypi.org/project/music21) · [Docs](https://www.music21.org/music21docs/)

Provides tools for computer-aided musical analysis and score processing.

- Downloads / mo: 972.5K
- Stars: 2.6K
- Last release: 10.5.2
- License: BSD-3-Clause
- Capabilities: [From the music21 docs](https://www.music21.org/music21docs/)

**Strengths**

- **Structures notes into musical streams.** Place notes and nested musical content inside Stream containers.
- **Imports and exports score notation.** Read and write MusicXML alongside MIDI and other music formats.

**Watch out for**

- **Graphical notation needs external software.** Configure a supported score viewer before calling graphical show.

```sh
python -m pip install music21
```

**MusicLang/musiclang** (207 stars)

[MusicLang/musiclang](https://github.com/MusicLang/musiclang) 

```python
def _m21Parse(f, fmt=None, remove_perc=True):
    """

    Parameters
    ----------
    f :

    fmt :
         (Default value = None)

    Returns
    -------

    """
    import music21
    s = music21.converter.parse(f, format=fmt, forceSource=True)
    if remove_perc:

        for el in s.recurse():
            if set(el.classes).intersection(['PercussionChord', 'Unpitched']):  # or 'Piano'
                # el.activeSite.replace(el, instrument.Violin())
                el.activeSite.remove(el)

        # perc = [
        #     p
        #     for p in s.parts
        #     if list(p.recurse().getElementsByClass(["PercussionClef", "PercussionChord"]))
        # ]
        # s.remove(perc, recurse=True)
    return s
```

[musiclang/analyze/parser.py](https://github.com/MusicLang/musiclang/blob/6d1f4afc88cdbc7be3635862cafd980e41e77f67/musiclang/analyze/parser.py#L640-L669) · [More projects using music21 →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20music21%20for%20MIDI%20serialization%2C%20score%20parsing%20and%20note-event%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from music21 import note
n = note.Note('C4')
print(n)

```

From [README.md](https://www.music21.org/music21docs/moduleReference/moduleNote.html)

### pretty_midi

[GitHub](https://github.com/craffel/pretty-midi) · [PyPI](https://pypi.org/project/pretty-midi) · [Docs](https://pypi.org/project/pretty-midi/)

Represents MIDI instruments and note events for analysis, editing, and synthesis.

- Downloads / mo: 690.8K
- Stars: 1.0K
- Last release: 0.2.11.post0
- License: MIT
- Capabilities: [From the pretty_midi docs](https://pypi.org/project/pretty-midi/)

**Strengths**

- **Uses seconds for note timing.** Read note start and end positions in absolute seconds.
- **Builds piano-roll note matrices.** Convert instrument notes into a matrix of pitch activity over time.

**Watch out for**

- **Basic waveform synthesis omits drums.** Use a drum-capable synthesizer to render percussion.

```sh
python -m pip install pretty-midi
```

**magenta/note-seq** (237 stars)

[magenta/note-seq](https://github.com/magenta/note-seq) 

```python
def midi_to_note_sequence(midi_data):
  """Convert MIDI file contents to a NoteSequence.

  Converts a MIDI file encoded as a string into a NoteSequence. Decoding errors
  are very common when working with large sets of MIDI files, so be sure to
  handle MIDIConversionError exceptions.

  Args:
    midi_data: A string containing the contents of a MIDI file or populated
        pretty_midi.PrettyMIDI object.

  Returns:
    A NoteSequence.

  Raises:
    MIDIConversionError: An improper MIDI mode was supplied.
  """
  # In practice many MIDI files cannot be decoded with pretty_midi. Catch all
  # errors here and try to log a meaningful message. So many different
  # exceptions are raised in pretty_midi.PrettyMidi that it is cumbersome to
  # catch them all only for the purpose of error logging.
  # pylint: disable=bare-except
  if isinstance(midi_data, pretty_midi.PrettyMIDI):
    midi = midi_data
  else:
    try:
      midi = pretty_midi.PrettyMIDI(io.BytesIO(midi_data))
    except:
      raise MIDIConversionError('Midi decoding error %s: %s' %
                                (sys.exc_info()[0], sys.exc_info()[1]))
  # pylint: enable=bare-except

  sequence = music_pb2.NoteSequence()

  # Populate header.
  sequence.ticks_per_quarter = midi.resolution
  sequence.source_info.parser = music_pb2.NoteSequence.SourceInfo.PRETTY_MIDI
  sequence.source_info.encoding_type = (
      music_pb2.NoteSequence.SourceInfo.MIDI)

  # Populate time signatures.
  for midi_time in midi.time_signature_changes:
    time_signature = sequence.time_signatures.add()
    time_signature.time = midi_time.time
    time_signature.numerator = midi_time.numerator
    try:
      # Denominator can be too large for int32.
      time_signature.denominator = midi_time.denominator
    except ValueError:
      raise MIDIConversionError('Invalid time signature denominator %d' %
                                midi_time.denominator)

  # Populate key signatures.
  for midi_key in midi.key_signature_changes:
    key_signature = sequence.key_signatures.add()
    key_signature.time = midi_key.time
    key_signature.key = midi_key.key_number % 12
    midi_mode = midi_key.key_number // 12
    if midi_mode == 0:
      key_signature.mode = key_signature.MAJOR
    elif midi_mode == 1:
      key_signature.mode = key_signature.MINOR
    else:
      raise MIDIConversionError('Invalid midi_mode %i' % midi_mode)

  # Populate tempo changes.
  tempo_times, tempo_qpms = midi.get_tempo_changes()
  for time_in_seconds, tempo_in_qpm in zip(tempo_times, tempo_qpms):
    tempo = sequence.tempos.add()
    tempo.time = time_in_seconds
    tempo.qpm = tempo_in_qpm

  # Populate notes by gathering them all from the midi's instruments.
  # Also set the sequence.total_time as the max end time in the notes.
  midi_notes = []
  midi_pitch_bends = []
  midi_control_changes = []
  for num_instrument, midi_instrument in enumerate(midi.instruments):
    # Populate instrument name from the midi's instruments
    if midi_instrument.name:
      instrument_info = sequence.instrument_infos.add()
      instrument_info.name = midi_instrument.name
      instrument_info.instrument = num_instrument
    for midi_note in midi_instrument.notes:
      if not sequence.total_time or midi_note.end > sequence.total_time:
        sequence.total_time = midi_note.end
      midi_notes.append((midi_instrument.program, num_instrument,
                         midi_instrument.is_drum, midi_note))
    for midi_pitch_bend in midi_instrument.pitch_bends:
      midi_pitch_bends.append(
          (midi_instrument.program, num_instrument,
           midi_instrument.is_drum, midi_pitch_bend))
    for midi_control_change in midi_instrument.control_changes:
      midi_control_changes.append(
          (midi_instrument.program, num_instrument,
           midi_instrument.is_drum, midi_control_change))

  for program, instrument, is_drum, midi_note in midi_notes:
    note = sequence.notes.add()
    note.instrument = instrument
    note.program = program
    note.start_time = midi_note.start
    note.end_time = midi_note.end
    note.pitch = midi_note.pitch
    note.velocity = midi_note.velocity
    note.is_drum = is_drum

  for program, instrument, is_drum, midi_pitch_bend in midi_pitch_bends:
    pitch_bend = sequence.pitch_bends.add()
    pitch_bend.instrument = instrument
    pitch_bend.program = program
    pitch_bend.time = midi_pitch_bend.time
    pitch_bend.bend = midi_pitch_bend.pitch
    pitch_bend.is_drum = is_drum

  for program, instrument, is_drum, midi_control_change in midi_control_changes:
    control_change = sequence.control_changes.add()
    control_change.instrument = instrument
    control_change.program = program
    control_change.time = midi_control_change.time
    control_change.control_number = midi_control_change.number
    control_change.control_value = midi_control_change.value
    control_change.is_drum = is_drum

  # TODO(douglaseck): Estimate note type (e.g. quarter note) and populate
  # note.numerator and note.denominator.

  return sequence
```

[note_seq/midi_io.py](https://github.com/magenta/note-seq/blob/35825508885343fb06f93dc87ff491dbbf034505/note_seq/midi_io.py#L43-L170) · [More projects using pretty_midi →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pretty-midi%20for%20MIDI%20serialization%2C%20score%20parsing%20and%20note-event%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import pretty_midi
midi = pretty_midi.PrettyMIDI('example.mid')
print(midi.get_end_time())

```

From [README.md](https://github.com/craffel/pretty-midi/blob/0df351ff2949ef80e788343e952fe15e473f0cde/pretty_midi/pretty_midi.py)

### Symusic

[GitHub](https://github.com/Yikai-Liao/symusic) · [PyPI](https://pypi.org/project/symusic) · [Docs](https://pypi.org/project/symusic/)

Parses MIDI files through a high-performance interface.

- Downloads / mo: 463.8K
- Stars: 190
- Last release: 0.6.0
- License: MIT
- Capabilities: [From the Symusic docs](https://pypi.org/project/symusic/)

```sh
python -m pip install symusic
```

**Natooz/MidiTok** (908 stars)

[Natooz/MidiTok](https://github.com/Natooz/MidiTok) 

```python
def split_score_per_tracks(score: Score) -> list[Score]:
    """
    Split a ``symusic.Score`` into several scores for each of its tracks.

    The split scores will all start at tick 0.
    Example: for a score with an end tick at 1000, and a list of tick
    ``[2000, 5000, 7000]``, this method will return a list of four scores which
    correspond respectively to the portions of the original score from tick 0 to 2000,
    2000 to 5000, 5000 to 7000 and 10000 to 10000.

    :param score: ``symusic.Score`` object to split.
    :return: a list of split ``symusic.Score`` objects.
    """
    scores_split = []
    for track in score.tracks:
        score_split = Score(score.tpq)
        score_split.tempos = score.tempos
        score_split.time_signatures = score.time_signatures
        score_split.key_signatures = score.key_signatures
        score_split.markers = score.markers
        score_split.tracks.append(track.copy())

        scores_split.append(score_split)
    return scores_split
```

[src/miditok/utils/split.py](https://github.com/Natooz/MidiTok/blob/680b5a4ec1b2ebd2e55f229ffcfce7f4770a2411/src/miditok/utils/split.py#L563-L586) · [More projects using Symusic →](https://dashboard.exa.ai/playground/search?q=symusic%20GitHub%20projects)

**Quickstart**

```python
from symusic import Score
score = Score('example.mid')
print(score.tpq)

```

From [README.md](https://pypi.org/pypi/symusic/0.6.0/json#info.description)

### Basic Pitch

[GitHub](https://github.com/spotify/basic-pitch) · [PyPI](https://pypi.org/project/basic-pitch) · [Docs](https://pypi.org/project/basic-pitch/)

Converts audio to MIDI and detects pitch bends.

- Downloads / mo: 396.1K
- Stars: 6.1K
- Last release: 0.4.0
- License: Apache-2.0
- Capabilities: [From the Basic Pitch docs](https://pypi.org/project/basic-pitch/)

```sh
python -m pip install basic-pitch
```

**samim23/polymath** (1.6K stars)

[samim23/polymath](https://github.com/samim23/polymath) 

```python
def extractMIDI(audio_paths, output_dir):
    print('- Extract Midi')
    save_midi = True
    sonify_midi = False
    save_model_outputs = False
    save_notes = False

    predict_and_save(audio_path_list=audio_paths, 
                  output_directory=output_dir, 
                  save_midi=save_midi, 
                  sonify_midi=sonify_midi, 
                  save_model_outputs=save_model_outputs, 
                  save_notes=save_notes)
```

[polymath.py](https://github.com/samim23/polymath/blob/49e56436ae8127105f4195dd83b39f7093430e27/polymath.py#L333-L345) · [More projects using Basic Pitch →](https://dashboard.exa.ai/playground/search?q=basic-pitch%20GitHub%20projects)

**Quickstart**

```python
from basic_pitch.inference import predict
model_output, midi_data, note_events = predict('example.wav')
print(len(note_events))

```

From [inference.py](https://github.com/spotify/basic-pitch/blob/9991303bba609a3b93089d13ec80d1d495083596/basic_pitch/inference.py)

### python-rtmidi

[GitHub](https://github.com/SpotlightKid/python-rtmidi) · [PyPI](https://pypi.org/project/python-rtmidi) · [Docs](https://spotlightkid.github.io/python-rtmidi/)

Binds the RtMidi C++ library to Python with Cython.

- Downloads / mo: 207.1K
- Stars: 417
- Last release: 1.5.8
- License: MIT
- Capabilities: [From the python-rtmidi docs](https://spotlightkid.github.io/python-rtmidi/)

```sh
python -m pip install python-rtmidi
```

**mido/mido** (1.7K stars)

[mido/mido](https://github.com/mido/mido) 

```python
def get_devices(api=None, **kwargs):
    devices = {}

    rtapi = _get_api_id(api)

    mi = rtmidi.MidiIn(rtapi=rtapi)
    mo = rtmidi.MidiOut(rtapi=rtapi)
    input_names = mi.get_ports()
    output_names = mo.get_ports()

    for name in input_names + output_names:
        if name not in devices:
            devices[name] = {
                'name': name,
                'is_input': name in input_names,
                'is_output': name in output_names,
            }

    mi.delete()
    mo.delete()
    return list(devices.values())
```

[mido/backends/rtmidi.py](https://github.com/mido/mido/blob/d261ee41db32717fb73dfaa14162159fb6529ef5/mido/backends/rtmidi.py#L51-L71) · [More projects using python-rtmidi →](https://dashboard.exa.ai/playground/search?q=python-rtmidi%20GitHub%20projects)

**Quickstart**

```python
import rtmidi
midiout = rtmidi.MidiOut()
try:
    print(midiout.get_ports())
finally:
    midiout.delete()

```

From [rtmidi.rst](https://spotlightkid.github.io/python-rtmidi/rtmidi.html)

### Essentia

[GitHub](https://github.com/MTG/essentia) · [PyPI](https://pypi.org/project/essentia) · [Docs](http://essentia.upf.edu)

Analyzes, describes, and synthesizes audio and music.

- Downloads / mo: 116.3K
- Stars: 3.8K
- Last release: 2.1b6.dev1438
- License: AGPL-3.0-only
- Capabilities: [From the Essentia docs](http://essentia.upf.edu)

```sh
python -m pip install essentia==2.1b6.dev1438
```

**Quickstart**

```python
import numpy as np
from essentia.standard import Audio2Midi
detector = Audio2Midi(hopSize=32)
result = detector(np.zeros(32, dtype=np.float32))
print(result[2:])

```

From [README.md](https://essentia.upf.edu/reference/std_Audio2Midi.html) · [Find projects using Essentia →](https://dashboard.exa.ai/playground/search?q=essentia%20GitHub%20projects)

## FAQ

### Which Python music library should I use?

[Mido](#mido) suits MIDI messages and files. [music21](#music) suits score analysis with notation, parts, and durations. [Pedalboard](#pedalboard) suits audio effects and rendering instrument plugins.

### What is Basic Pitch?

[Basic Pitch](#basic-pitch) converts audio recordings to MIDI and detects pitch bends. Its maintainers recommend it for one instrument at a time.

### What is music21?

[music21](#music) is a toolkit for computer-aided music analysis that represents music as scores, parts, and streams. It reads MusicXML, MIDI, and other symbolic formats.

### How do I make music with Python?

[Pedalboard](#pedalboard) adds effects to audio and renders sound from installed instrument plugins. [Symusic](#symusic) synthesizes MIDI through SoundFont files.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python music libraries Mido pretty_midi Miditoolkit music21 code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
