OpenMed Dependencies: Complete Guide to Core and Optional Packages
OpenMed requires only pysbd and faker for core functionality, but offers eight optional dependency groups—including Hugging Face transformers, MLX, FastAPI, and GLiNER—that enable model inference, REST APIs, and documentation generation.
OpenMed is a flexible medical NLP toolkit hosted at maziyarpanahi/openmed that uses a minimal core installation strategy to keep base requirements lightweight. Understanding the complete OpenMed dependencies structure is essential for deploying the right components, whether you need basic sentence segmentation or Apple Silicon-accelerated model serving. All dependency specifications are declared centrally in the project's pyproject.toml file.
Core Runtime Dependencies
The base installation of OpenMed installs only two essential packages defined in pyproject.toml.
Sentence Segmentation with pysbd
The pysbd>=0.3.4,<0.4 library handles sentence boundary detection for clinical text. This dependency is imported and used throughout the codebase for preprocessing unstructured medical documents.
import pysbd
seg = pysbd.Segmenter(language="en", clean=True)
text = "Patient reports headache. No fever."
sentences = seg.segment(text)
print(sentences) # ['Patient reports headache.', 'No fever.']
Synthetic Data Generation with faker
The faker>=22.0 package provides utilities for generating synthetic clinical data during testing and demonstration workflows.
Optional Dependency Groups
OpenMed organizes extended functionality into optional extras that you install via bracket notation (e.g., pip install openmed[cli]).
CLI Tools (rich, typer)
The CLI extras group installs rich>=13.0 for formatted terminal output and typer>=0.12 for the command-line interface implementation found in openmed/cli/typer_app.py.
openmed --help # Shows the Typer-based help menu
openmed run --model gpt4 # Example command using the CLI extras
Model Inference (transformers, accelerate)
The hf group enables Hugging Face model loading and acceleration:
transformers>=4.50huggingface-hub>=0.30accelerate>=0.29tokenizers>=0.15
These packages support loading pretrained medical models and optimizing inference pipelines.
MLX Backend (Apple Silicon)
The MLX backend group targets Apple Silicon devices using Apple's MLX framework:
mlx>=0.22huggingface-hub>=0.30transformers>=4.50tokenizers>=0.15safetensors>=0.4tiktoken>=0.7
This configuration enables high-performance inference on M-series chips without requiring PyTorch.
CoreML Export (coremltools, torch)
The CoreML export group facilitates converting PyTorch models to Apple's Core ML format:
coremltools>=8.0torch>=2.0transformers>=4.50
Entity Extraction (gliner)
The GLiNER group adds fast, token-aware named entity recognition:
gliner[tokenizers]>=0.2.0torch>=2.0
FastAPI Service (fastapi, uvicorn)
The service group powers the REST API server implemented in openmed/mcp/server.py:
fastapi>=0.110uvicorn[standard]>=0.29
uvicorn openmed.mcp.server:app --host 0.0.0.0 --port 8000
MCP Utilities (mcp)
The MCP group includes mcp>=1.9 for model-component-pipeline helper functions.
Documentation (mkdocs)
The docs group generates the project website and includes:
mkdocs>=1.6mkdocs-material>=9.5mkdocs-git-revision-date-localized-plugin>=1.2.6mkdocs-minify-plugin>=0.8.0pymdown-extensions>=10.8
Development Tools (pytest, flake8)
The development group supports testing and quality assurance:
flake8>=7.0(linting)pytest>=7.0(test execution)pytest-cov>=4.0(coverage reporting)httpx>=0.27(HTTP client utilities)
Installation Examples
Install only the core OpenMed dependencies for minimal footprint:
pip install openmed
Install multiple optional groups to enable full functionality:
# Full feature set (CLI + Hugging Face + FastAPI + docs)
pip install "openmed[cli,hf,service,docs]"
Target specific backends based on your hardware:
# For Apple Silicon MLX acceleration
pip install "openmed[mlx]"
# For CoreML model export
pip install "openmed[coreml]"
Key Configuration Files
The dependency structure is controlled by these critical files in the repository:
pyproject.toml– Central declaration of core and optional dependencies, version constraints, and extras groupsopenmed/__about__.py– Package version metadata referenced during installationopenmed/cli/typer_app.py– Implementation of the CLI interface requiring thecliextrasopenmed/mcp/server.py– FastAPI application requiring theserviceextras
Summary
- Core dependencies are limited to
pysbd(sentence segmentation) andfaker(synthetic data), keeping the base installation lightweight. - Eight optional groups extend functionality:
cli,hf,mlx,coreml,gliner,service,mcp, anddocs. - Hardware-specific groups include
mlxfor Apple Silicon andcoremlfor mobile deployment. - Development tools are isolated in a separate group containing
pytest,flake8, andhttpx. - All constraints are defined in
pyproject.tomlwith specific minimum versions (e.g.,transformers>=4.50).
Frequently Asked Questions
What are the minimum OpenMed dependencies required to run the package?
The absolute minimum installation requires only pysbd>=0.3.4,<0.4 and faker>=22.0. These provide sentence boundary detection and synthetic data generation capabilities without any machine learning frameworks.
How do I install OpenMed with Hugging Face model support?
Install the hf optional group using pip install "openmed[hf]". This adds transformers>=4.50, huggingface-hub>=0.30, accelerate>=0.29, and tokenizers>=0.15 to enable loading and running Hugging Face transformer models.
Can I run OpenMed on Apple Silicon without installing PyTorch?
Yes. Install the mlx optional group (pip install "openmed[mlx]") to use Apple's MLX framework for acceleration. This group includes mlx>=0.22 and related Hugging Face utilities but does not require PyTorch, making it ideal for M-series Macs.
Which dependency group is needed for the OpenMed REST API server?
The service group provides the required fastapi>=0.110 and uvicorn[standard]>=0.29 packages. Install with pip install "openmed[service]" and launch the server using the uvicorn openmed.mcp.server:app command.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →