unimodpy
unimodpy wraps the UNIMOD mass-spectrometry modifications database in a typed Python API, so proteomics tooling can look up modifications by ID, name, mass, or specificity without writing an OBO parser or re-deriving elemental formulas by hand. It ships with the full database bundled in, so it works fully offline.
Highlights
- Bundled, offline data — 1,561 UNIMOD terms shipped with the package; no network calls needed
- Zero core dependencies — pure Python,
pip installand go - Typed, immutable models with
py.typed(PEP 561) for IDE autocomplete and static checking - Rich lookups — by numeric ID,
UNIMOD:Naccession, exact name, or free-text search across names, definitions, and synonyms - Full specificity data — site, position, and classification rules (with neutral losses) for every modification
- Formula and mass helpers computed for you (elemental composition dicts, ProForma-style formula strings)
- Round-trip export to TSV/CSV and back to OBO
- Online browser — search, sort, and inspect every term, no install required
- Optional local FastAPI + MCP server (
pip install unimodpy[server]) to expose the database over HTTP or to LLM tools
Install
pip install unimodpy
Or with uv:
uv add unimodpy
Requires Python 3.12+. No third-party dependencies for the core package.
Quick Example
import unimodpy
db = unimodpy.load() # bundled UNIMOD database, no download needed
print(len(db)) # 1561
# Lookup by integer ID, "UNIMOD:N" accession, or subscript
acetyl = db.get_by_id(1)
print(acetyl.id, acetyl.name, acetyl.delta_mono_mass, acetyl.proforma_formula)
# 1 Acetyl 42.010565 C2H2O
# Lookup by exact name (case-insensitive)
phospho = db.get_by_name("Phospho")
# Full-text search across name, definition, and synonyms
hits = db.search("glycosyl")
print(len(hits)) # 6
# Entries whose delta_mono_mass is within 0.01 Da of 79.966, on S, T or Y
for entry, error in db.search_mass(79.966, site="STY"):
print(entry.name, round(error, 4)) # Phospho -0.0003, Sulfo 0.0092
db.search_mass(79.966331, tolerance=0.005) # [(Phospho, ~0.0)]: Sulfo is 9.5 mDa away
# Per-site specificity rules (position, classification, neutral losses)
entry = db.get_by_name("Carbamidomethyl")
print(entry.dict_composition) # {'H': 3, 'C': 2, 'N': 1, 'O': 1}
for spec in entry.specificities[:1]:
print(spec.site, spec.position, spec.classification)
# C Anywhere Chemical derivative
More
Refreshing from unimod.org, filtering, TSV/CSV export, OBO round-trip
# Download the latest OBO and use it immediately
db = unimodpy.load(refresh=True)
# Or just download the file
path = unimodpy.download() # ~/.cache/unimodpy/UNIMOD.obo (reused if present)
path = unimodpy.download("/my/dir/UNIMOD.obo") # custom destination
path = unimodpy.download(force=True) # always re-download
# Write every entry to TSV (or CSV)
db.write_tsv("unimod.tsv")
db.write_tsv("unimod.csv", delimiter=",")
# Round-trip back to UNIMOD OBO format
db.write_obo("out/UNIMOD.obo")
db2 = unimodpy.parse_obo("out/UNIMOD.obo") # identical entry count and fields
TSV/CSV columns
write_tsv writes one row per entry with the following columns, in this order.
Missing values are empty cells. Multi-valued cells use "; " between values,
independently of whether the file delimiter is a tab or comma. The last four columns, like
specificities_hidden, hold one slot per entry of specificities: splitting any of them and
specificities itself on "; " always gives lists of the same length. An entry with no
specificities leaves all six of those cells empty, where that split gives a single empty slot
rather than none; UNIMOD:0, the root node, is the only such entry in the bundled database.
| Column | Contents |
|---|---|
id |
Accession in UNIMOD:N form. |
name |
Modification name. |
definition |
Modification definition. |
synonyms |
Synonyms joined with "; ". |
comment |
Free-text comment. |
record_id |
Numeric UNIMOD record ID. |
delta_mono_mass |
Monoisotopic mass difference in Da. |
delta_avge_mass |
Average mass difference in Da. |
delta_composition |
UNIMOD's elemental-composition string. |
username_of_poster |
Submitter username. |
group_of_poster |
Submitter group. |
date_time_posted |
Submission timestamp as YYYY-MM-DD HH:MM:SS. |
date_time_modified |
Last modification timestamp in the same format. |
approved |
1 if approved, 0 if not, or empty if unspecified. |
is_a |
Parent accession in UNIMOD:N form. |
specificities |
Every site:position:classification triple, including hidden ones, joined with "; ". |
specificities_hidden |
One 1 (hidden) or 0 (visible) per specificity, in the same order, joined with "; ". |
definition_ref |
The citation list from the definition line, exactly as OBO writes it, backslash escapes included: PMID:10504701, UNIMODURL:http\://www.unimod.org/modifications_view.php?editid1=8. |
synonym_scopes |
OBO scope of each synonym, in the same order as synonyms, joined with "; ". |
specificities_spec_num |
The UNIMOD specificity number of each specificity, in the same order, joined with "; ". |
specificities_group |
The specificity group number of each specificity (not the submitter's group_of_poster), in the same order, joined with "; ". |
specificities_misc_notes |
The free-text note of each specificity, in the same order, joined with "; "; an empty slot where there is none. %, ; and | in a note are escaped as %25, %3B and %7C. |
specificities_neutral_losses |
The neutral losses of each specificity, in the same order, joined with "; "; an empty slot where there are none. Within a slot, losses are joined with |, each as key:mono_mass:avge_mass:flag:composition (flag is 1 or 0). The composition is UNIMOD's string, for example H(3) O(4) P, with %, ; and | escaped as above and : escaped as %3A, so a loss always splits into exactly five fields. |
Local HTTP API and MCP server (pip install unimodpy[server])
pip install unimodpy[server]
uvicorn unimodpy.server.app:app --reload
This starts a FastAPI app exposing the database as both a JSON REST API
(GET /api/entries/{id}, /api/search, /api/entries/by-name/{name}, …)
and an MCP endpoint at POST /mcp with
get_by_id, get_by_name, and search tools, for pointing LLM clients
directly at UNIMOD:
claude mcp add unimod http://localhost:8000/mcp --transport http
Full API reference
| Symbol | Description |
|---|---|
load(source=None, *, refresh=False, cache=False) |
Load the database. No args → bundled file. refresh=True → download first (not together with source: ValueError). cache=True → parse the bundled file once and return the same (read-only) database on later calls. |
download(dest=None, *, force=False) |
Download latest OBO from unimod.org; returns Path. An existing file is reused unless force=True. |
parse_obo(path) |
Low-level: parse any OBO file at path. |
write_tsv(entries, path, *, delimiter) |
Write entries to a TSV (or CSV) file. |
write_obo(entries, path, *, header_lines) |
Write entries back to UNIMOD OBO format. |
UnimodDatabase |
Iterable collection with get_by_id, get_by_name, search, get_by_site, search_mass, write_tsv(), write_obo(), __getitem__. Also exposes header_lines. |
UnimodDatabase.search_mass(delta, *, tolerance=0.01, tolerance_unit="da", site=None, position=None) |
(entry, delta - delta_mono_mass) pairs within tolerance Da (edges inclusive), closest first. site may list several residues ("STY"); get_by_site(site) takes exactly one. |
UnimodEntry |
Frozen dataclass for one modification term. Includes definition_ref (bracketless, "" if none), synonym_scopes (the OBO scope of each entry of synonyms, by position, as a raw token such as RELATED), the accession property ("UNIMOD:21"), and get_mass(*, monoisotopic=True) (delta_mono_mass, or delta_avge_mass with monoisotopic=False). |
Specificity |
Frozen dataclass for one site/position rule. |
NeutralLoss |
Frozen dataclass for one neutral loss. |
Site |
StrEnum of amino acid residues and termini. |
Position |
StrEnum of sequence position constraints. |
Classification |
StrEnum of modification classes. |
UnimodError, UnimodParseError, UnimodKeyError |
Package exceptions; UnimodParseError is also a ValueError, UnimodKeyError (raised by db[key] on a miss) is also a KeyError. |
See CHANGELOG.md
for release history.
Data Source
Term data comes from the UNIMOD protein modification database (Creasy & Cottrell, Proteomics 2004). See unimod.org for the database's own license and citation guidance.
Related Projects
Part of the tacular-omics family of proteomics PTM-vocabulary packages:
| Package | Description |
|---|---|
| psimodpy | Parse and query the PSI-MOD protein modification ontology |
| uniprotptmpy | Parse and query the UniProt PTM controlled vocabulary |
| tacular | Broader MS-proteomics lookup library (amino acids, elements, fragment-ion masses) that bundles its own copies of UNIMOD alongside PSI-MOD, RESID, XLMOD, GNOme, and UniProt-PTM; the base library for peptacular and paftacular |
Citation
If unimodpy is useful in your research, please cite it — see
CITATION.cff
or use the "Cite this repository" button on GitHub. Releases are archived on
Zenodo (DOI badge above).
License
Metadata
Release files for unimodpy 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unimodpy-1.3.0.tar.gz | 241.3 kB | With provenance | Details for unimodpy-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| unimodpy-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for unimodpy-1.3.0-py3-none-any.whl |
Total release size: 431.6 kB
Release files / unimodpy-1.3.0.tar.gz
| Download URL | unimodpy-1.3.0.tar.gz |
|---|---|
| Size | 241.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7955817f57ae43c49edfbedb0bc0e277c90300877a7acb242cb5a5aa67f2bed8
|
|
BLAKE2b-256 checksum How to use checksums |
c45b3722ea6cbda420b68cb037dd2468ac000dcaa0ae2f698ae03fe02a7e26ad
|
| 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 17, 2026.
Transparency logRelease files / unimodpy-1.3.0-py3-none-any.whl
| Download URL | unimodpy-1.3.0-py3-none-any.whl |
|---|---|
| Size | 190.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26eb0eed7ff55442510110cdf9dfbed62c03eb329281e18f10550393f4e4537e
|
|
BLAKE2b-256 checksum How to use checksums |
04021cb3ab7bb05a55023737aed985eaa2b1968f575327ff5f5557ba43ba5174
|
| 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 17, 2026.
Transparency logSecurity for unimodpy 1.3.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.
Attestation for unimodpy-1.3.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 17, 2026.
Transparency logA 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.