Skip to main content

PicoMidi Logo

PicoMidi

A lightweight, focused MIDI library for Python

License: MIT Python


Overview

PicoMidi provides core MIDI protocol functionality with a clean, type-safe API. Built for developers who need reliable MIDI message handling without the bloat.

Features

  • Type-safe MIDI values: Note, Velocity, ControlValue, ProgramNumber, PitchBendValue
  • Message classes: NoteOn, NoteOff, ControlChange, ProgramChange, PitchBend
  • Parser: Convert raw MIDI bytes to message objects
  • Utilities: Value conversions, validation, formatting, timing calculations
  • Core constants: Status bytes, channels, bitmasks

Installation

pip install picomidi

Quick Start

Creating Messages

from picomidi import NoteOn, NoteOff, ControlChange, ProgramChange, PitchBend
from picomidi.core import Channel, Note, Velocity, ControlValue, ProgramNumber, PitchBendValue

# Create a Note On message (Middle C, full velocity, channel 1)
note_on = NoteOn(
    channel=Channel.CH1,
    note=Note(60),  # Middle C
    velocity=Velocity(127)
)

# Convert to bytes
bytes_data = note_on.to_bytes()  # b'\x90<\x7f'

# Convert to hex string
hex_str = note_on.to_hex_string()  # "90 3C 7F"

Using Note Names

from picomidi.core import Note

# Create note from name
note = Note.from_name("C4")  # Middle C
note = Note.from_name("A#3")  # A sharp, octave 3
note = Note.from_name("Bb5")  # B flat, octave 5

# Convert to name
name = note.to_name()  # "C4"
name = note.to_name(use_sharps=False)  # "Db4" instead of "C#4"

Parsing Messages

from picomidi.parser import Parser

parser = Parser()

# Feed raw MIDI bytes
raw_bytes = b'\x90<\x7f'  # Note On message
for message in parser.feed(raw_bytes):
    print(message)  # NoteOn(channel=1, note=Note(C4), velocity=127)
    print(message.to_hex_string())  # "90 3C 7F"

Value Conversions

from picomidi.utils.conversion import (
    combine_7bit_msb_lsb,
    split_14bit_to_7bit,
    clamp_midi_value
)

# Combine two 7-bit values into 14-bit
msb, lsb = 0x40, 0x20
value_14bit = combine_7bit_msb_lsb(msb, lsb)  # 8256

# Split 14-bit value
msb, lsb = split_14bit_to_7bit(value_14bit)  # (64, 32)

# Clamp values
clamped = clamp_midi_value(200)  # 127 (max MIDI value)

Timing Calculations

from picomidi.utils.timing import (
    bpm_to_microseconds_per_quarter,
    ticks_to_milliseconds
)

# Convert BPM to microseconds per quarter note (for MIDI files)
usec = bpm_to_microseconds_per_quarter(120)  # 500000

# Convert ticks to milliseconds
ms = ticks_to_milliseconds(
    ticks=480,
    ticks_per_beat=480,
    bpm=120
)  # 1000.0 (1 second)

Project Structure

picomidi/
├── core/           # Core protocol definitions
│   ├── bitmask.py  # Bit masks
│   ├── constant.py # MIDI constants
│   ├── status.py   # Status bytes
│   ├── channel.py  # Channel handling
│   └── types.py    # Type-safe value classes
├── message/        # Message classes
│   ├── base.py     # Base message class
│   └── channel_voice/  # Channel voice messages
├── parser/         # Message parsing
│   └── parser.py   # Parser implementation
└── utils/          # Utilities
    ├── conversion.py  # Value conversions
    ├── validation.py  # Value validation
    ├── formatting.py  # Message formatting
    └── timing.py      # Timing calculations

Design Principles

  1. Lightweight: Minimal dependencies, focused on core MIDI protocol
  2. Type-safe: Use dataclasses and type hints throughout
  3. Composable: Messages can be easily combined and extended
  4. Well-tested: Each module should have comprehensive tests
  5. Documented: Clear docstrings and examples

License

This project is licensed under the MIT License - see the LICENSE file for details.


Made with ❤️ for the MIDI community

Metadata

Release files for picomidi 0.2.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 picomidi 0.2.0
File Size Uploaded Provenance Actions
picomidi-0.2.0.tar.gz 50.2 kB With provenance Details for picomidi-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 117.4 kB

Release files / picomidi-0.2.0.tar.gz

Download URL picomidi-0.2.0.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5879515dd20e6e466779e01f641fbbe00233f576cbf55d323275b46d65193552
BLAKE2b-256 checksum
How to use checksums
b87161434047d257613395cd3470b8bf92b19e3790ac96845a85536f12c83937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Release files / picomidi-0.2.0-py3-none-any.whl

Download URL picomidi-0.2.0-py3-none-any.whl
Size 67.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd570d266678e7c0b23b2b3560f59ab075dcdee937d44c1a1109940d77e24e1a
BLAKE2b-256 checksum
How to use checksums
c29b4341e906c03434920c9e3f4976caae2cf4132fb08e66d155b3b5ff47beed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

Security for picomidi 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for picomidi-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 7, 2026.

Transparency log

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