Use the Python API
The CLI and the MCP server are thin wrappers around seven resolver functions.
You can call them directly from code that has dicom-standard-kb installed.
Example
Section titled “Example”from pathlib import Path
from dicom_kb.db.models import read_sqlitefrom dicom_kb.query.markdown import render_markdownfrom dicom_kb.query.resolver import attribute_values
db = Path.home() / ".cache/dicom-standard-kb/db/2026d.sqlite"with read_sqlite(db) as connection: response = attribute_values(connection, name="PatientSex", edition="2026d") print(response.status) print(render_markdown(response))read_sqlite opens the database read-only and closes it afterwards.
Resolvers
Section titled “Resolvers”All are importable from dicom_kb.query.resolver. Each takes an open
sqlite3.Connection as its first argument and keyword-only arguments after
it, including the edition the database holds.
| Function | Arguments | Tool |
|---|---|---|
element_usage |
name, edition, iod=None |
dicom_element |
iod_modules |
name, edition, expand=False, types=None, usage=None, module=None, page=1 |
dicom_iod |
module_attributes |
name, edition, detail="outline", types=None, page=1 |
dicom_module |
attribute_values |
name, edition, within=None, page=1 |
dicom_values |
code_lookup |
query, edition, scheme=None, page=1 |
dicom_code |
search_standard |
query, edition, part=None, limit=10 |
dicom_search |
read_standard |
reference, edition, page=1 |
dicom_read |
The response
Section titled “The response”Each resolver returns a ToolResponse from dicom_kb.query.answer_contracts:
| Field | Meaning |
|---|---|
status |
ok, not_found or validation_error |
result |
The answer’s data; for anything but ok, a message and maybe candidates |
refs |
StandardRef entries: part, section or table, and edition |
warnings |
Present only when the answer is missing something the source has |
The shape of result differs by resolver and is not a stable interface. Use
render_markdown(response) from dicom_kb.query.markdown for the same text
the CLI and MCP server return.