midi-structure
midi-structure is a lightweight Python package that provides a simple, structured interface for processing MIDI‑related text queries. It leverages llmatch‑messages to enforce that LLM responses conform to a predefined regex pattern, ensuring consistent and machine‑readable output.
Note: The package ships with a default LLM implementation (
ChatLLM7fromlangchain_llm7). You can also supply any LangChain‑compatible LLM (e.g., OpenAI, Anthropic, Google Generative AI) if you prefer.
🚀 Overview
- Structured MIDI queries – ask about instruments, file formats, protocol details, etc.
- Pattern‑based validation – responses are checked against a regex (
pattern) defined inprompts.py. - Pluggable LLM – use the built‑in
ChatLLM7or attach your own LangChain LLM. - Zero configuration – just pass a string and get a list of extracted data.
📦 Installation
pip install midi-structure
🛠️ Quick Start
from midi-structure import midi-structure
# Simple call using the default ChatLLM7 (reads API key from LLM7_API_KEY env var)
response = midi-structure(
user_input="What are the most common MIDI message types?"
)
print(response) # → a list of strings that match the defined pattern
Parameters
| Name | Type | Description |
|---|---|---|
user_input |
str |
The natural‑language query related to MIDI. |
llm |
Optional[BaseChatModel] |
A LangChain LLM instance. If omitted, ChatLLM7 is used. |
api_key |
Optional[str] |
API key for LLM7. If not supplied, the function looks for the LLM7_API_KEY environment variable. |
🔄 Using a Custom LLM
You can pass any LangChain‑compatible chat model. Below are a few examples.
OpenAI
from langchain_openai import ChatOpenAI
from midi-structure import midi-structure
llm = ChatOpenAI()
response = midi-structure("Explain the MIDI file header format.", llm=llm)
print(response)
Anthropic
from langchain_anthropic import ChatAnthropic
from midi-structure import midi-structure
llm = ChatAnthropic()
response = midi-structure("List the standard General MIDI instruments.", llm=llm)
print(response)
Google Generative AI
from langchain_google_genai import ChatGoogleGenerativeAI
from midi-structure import midi-structure
llm = ChatGoogleGenerativeAI()
response = midi-structure("How does MIDI time stamping work?", llm=llm)
print(response)
🔑 API Keys & Rate Limits
- LLM7 (default) offers a free tier that is sufficient for most typical usage.
- To obtain a free LLM7 API key, register at: https://token.llm7.io/
- You can provide the key in two ways:
- Set the environment variable
LLM7_API_KEY. - Pass it directly:
response = midi-structure("...", api_key="your_api_key")
- Set the environment variable
If you need higher rate limits, upgrade your LLM7 plan or switch to another LLM as shown above.
🧩 Project Structure
midi_structure/
│
├─ __init__.py # Exposes midi-structure function
├─ core.py # Implementation (the function shown above)
├─ prompts.py # Holds system/human prompts and regex pattern
└─ ... # Additional helper modules
The core function performs the following steps:
- Resolve the LLM (default =
ChatLLM7). - Build system and human messages from the supplied prompts.
- Compile the regex pattern.
- Call
llmatchto get a response that matches the pattern. - Return the extracted data as a list of strings.
🤝 Contributing
We welcome contributions! If you find a bug or have a feature request, please open an issue on GitHub:
Pull requests are encouraged. Please make sure tests pass and follow the existing code style.
📄 License
This project is licensed under the MIT License.
👤 Author
Eugene Evstafev
- Email: hi@euegne.plus
- GitHub: chigwell
- LinkedIn: Eugene Evstafev
Happy coding with MIDI!
Metadata
Release files for midi-structure 2025.12.20185411
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| midi_structure-2025.12.20185411.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| midi_structure-2025.12.20185411-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.7 kB
Release files / midi_structure-2025.12.20185411.tar.gz
| Download URL | midi_structure-2025.12.20185411.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac44c825da927f8e94a5e356ad4cbf81014cf2a17086a842478526506779b7ab
|
|
BLAKE2b-256 checksum How to use checksums |
0fec14697e48e2fd514ed4ec92fcf945b2014b6c320d9cddcab957de0b3bdc64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|
Release files / midi_structure-2025.12.20185411-py3-none-any.whl
| Download URL | midi_structure-2025.12.20185411-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3d79c8e3e1205ed69add8ff363b36a1f50904a82f3eb464729d3fc84f7a31570
|
|
BLAKE2b-256 checksum How to use checksums |
d6c9bb75c4ec2a83bb00cb42e1ddc6f585b5be5b5349b0c84cd2af3ce33fb6cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.11
|