Official Python client for the Medsplain TX medical text simplification API
Project description
Medsplain TX — Python SDK
Official Python client for the Medsplain TX medical text simplification API. Send clinical / medical text and get back a plain-language explanation.
Installation
pip install medsplain
Until this is published to PyPI, install from source — see Local development.
Quick start
from medsplain import Medsplain
client = Medsplain(api_key="mds_live_...")
result = client.translate("Patient presents with acute myocardial infarction.")
print(result.simplified_text)
print(f"{result.source_chars} chars in, {result.output_chars} chars out")
The client is a context manager, which closes the connection pool for you:
with Medsplain(api_key="mds_live_...") as client:
result = client.translate("CBC shows leukocytosis with left shift.")
print(result.simplified_text)
Configuration
| Argument | Env var | Default | Notes |
|---|---|---|---|
api_key |
MEDSPLAIN_API_KEY |
— | Required. Your mds_live_ key. |
base_url |
MEDSPLAIN_BASE_URL |
http://localhost:8000 |
API root, without the /v1 prefix. |
timeout |
— | 30.0 |
Per-request timeout in seconds. |
max_retries |
— | 2 |
Retries on connection errors, 429, and 5xx. |
import os
client = Medsplain(
api_key=os.environ["MEDSPLAIN_API_KEY"],
base_url="https://your-medsplain-host.example.com",
timeout=60.0,
)
API
translate(text, *, model=None) -> TranslationResult
Simplify medical text using the Claude-backed endpoint (POST /v1/translate).
text must be non-empty and at most 5000 characters.
translate_gemini(text, *, model=None) -> TranslationResult
Same contract, backed by Gemini (POST /v1/translate_test_gemini).
health_check() -> HealthStatus
Verify the API is reachable (GET /health-check).
TranslationResult
| Field | Type | Description |
|---|---|---|
original_text |
str |
Cleaned input text the server processed. |
simplified_text |
str |
The plain-language simplification. |
source_chars |
int |
Character count of the input. |
output_chars |
int |
Character count of the output. |
is_medical_text |
bool |
Whether the input was detected as medical. |
is_conversation |
bool |
Whether the input was detected as conversational. |
raw |
dict |
Full, unmodified response payload. |
Error handling
Every error inherits from MedsplainError. HTTP failures raise an APIStatusError
subclass chosen by status code:
from medsplain import (
Medsplain, AuthenticationError, RateLimitError,
PermissionDeniedError, APIStatusError,
)
client = Medsplain(api_key="mds_live_...")
try:
result = client.translate("...")
except AuthenticationError:
... # 401 — key missing/invalid/expired/revoked
except RateLimitError as e:
print("retry after", e.retry_after) # 429 — rate limit or token quota
except PermissionDeniedError:
... # 403 — no active plan / subscription
except APIStatusError as e:
print(e.status_code, e.code, e.message)
| Exception | Status | Meaning |
|---|---|---|
BadRequestError |
400 | Malformed request / validation error. |
AuthenticationError |
401 | API key missing, invalid, expired, or revoked. |
PermissionDeniedError |
403 | No active plan or subscription. |
NotFoundError |
404 | Resource not found. |
RateLimitError |
429 | Rate limit hit or token quota exhausted. |
ServerError |
5xx | Server-side failure. |
APIConnectionError |
— | The request never reached the server. |
Local development
cd sdk
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest # run tests
ruff check . # lint
mypy src/ # type-check
python -m build # build wheel + sdist into dist/
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medsplain-0.1.0.tar.gz.
File metadata
- Download URL: medsplain-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf5dd9ac5a0cce80cb23cf9fb0d11dc67a36ecebe68a59aefa4575a8995d9ba0
|
|
| MD5 |
c861d5a965f4ba3eebb5947f8df04517
|
|
| BLAKE2b-256 |
57cf9cf7fde60d6fe759b2bdb4fc9afdd933b9bc47ceb169a91c4b8a9ba93b5e
|
File details
Details for the file medsplain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: medsplain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6f2c46045bbd1811fc46f557128dec31e7d64dc2a61807271df48d82d2387a9
|
|
| MD5 |
8f85f45ec718f640d018c7eb729a72ec
|
|
| BLAKE2b-256 |
2d59499d46b3e7cb5460ba5b17fba8e1938ac799b692e5aaa89db61d1f2761d6
|