Official Python SDK for the Northlight Checker API — validate Russian electronic medical records against clinical guidelines.
Project description
northlight-checker
Official Python SDK for the Northlight Checker API — validate Russian electronic medical records (ЭМК) against clinical guidelines (Клинические рекомендации Минздрава РФ), quality criteria, МЭС, and more.
- Sync + async clients (
httpx) - Typed pydantic models that mirror the API schemas 1:1
- Automatic retries with exponential backoff +
Retry-Aftersupport - Typed exceptions for every HTTP failure mode
- Works with
NORTHLIGHT_API_KEYenv var out of the box
Install
pip install northlight-checker
Requires Python 3.10+. Core deps: httpx>=0.27, pydantic>=2.0.
30-second quick start
from northlight_checker import CheckerClient, MedicalRecord
with CheckerClient(api_key="nlt_...") as client:
result = client.validate(
medical_record=MedicalRecord(
diagnosis="E11 Сахарный диабет 2 типа",
diagnosis_code="E11",
anamnesis="Болеет 5 лет, компенсация неустойчивая.",
prescriptions=["Метформин 1000 мг 2 р/сут"],
examinations=["HbA1c 7.8%", "Глюкоза натощак 8.2"],
),
scope="case",
)
print(result.overall_score) # 0.0–1.0
print(result.critical_violations) # list[Violation]
print(result.summary) # narrative from the checker
Set NORTHLIGHT_API_KEY in your environment and you can drop api_key=...:
export NORTHLIGHT_API_KEY=nlt_live_xxx
from northlight_checker import CheckerClient
with CheckerClient() as client:
result = client.validate(medical_record=record, scope="case")
Async
import asyncio
from northlight_checker import AsyncCheckerClient, MedicalRecord
async def main() -> None:
async with AsyncCheckerClient() as client:
result = await client.validate(
medical_record=MedicalRecord(
diagnosis="I21.0 Острый трансмуральный инфаркт миокарда передней стенки",
diagnosis_code="I21.0",
anamnesis="Боли за грудиной 4 часа, ST-элевация.",
prescriptions=["Аспирин 300 мг", "Клопидогрел 600 мг", "Гепарин"],
examinations=["ЭКГ", "Тропонин I", "ЭхоКГ"],
),
scope="case",
application="CARDIO",
)
print(result.overall_score)
asyncio.run(main())
Batch
from northlight_checker import CheckerClient, MedicalRecord
records = [
MedicalRecord(diagnosis="E11 ...", anamnesis="..."),
MedicalRecord(diagnosis="I21 ...", anamnesis="..."),
]
with CheckerClient() as client:
results = client.validate_batch(records=records, scope="case")
for item in results:
if item.is_error:
print(item.index, "failed:", item.error)
else:
print(item.index, item.result.overall_score)
HTML report
from pathlib import Path
from northlight_checker import CheckerClient
with CheckerClient() as client:
html_bytes = client.validate_report(medical_record=record, scope="case")
Path("report.html").write_bytes(html_bytes)
Error handling
from northlight_checker import (
CheckerClient,
AuthError,
RateLimitError,
InsufficientBalanceError,
ValidationError,
ServerError,
NorthlightError,
)
try:
with CheckerClient() as client:
result = client.validate(medical_record=record, scope="case")
except AuthError:
# 401 / 403 — check your API key
raise
except InsufficientBalanceError:
# 402 — top up your prepaid balance
raise
except RateLimitError as e:
# 429 after retries — wait `e.retry_after` seconds or upgrade your plan
print("rate limited, wait", e.retry_after)
except ValidationError:
# 422 — request schema mismatch (caller bug)
raise
except ServerError:
# 5xx after retries exhausted
raise
except NorthlightError:
# base class for everything above + network errors
raise
Transient failures (429, 5xx, timeouts, connection errors) are retried
automatically up to 3 times with exponential backoff (1 s → 2 s → 4 s).
If the server sends a Retry-After header on 429, we honour it exactly.
4xx responses other than 429 are not retried — they mean your request
has a problem.
Other endpoints
with CheckerClient() as client:
scopes = client.list_scopes() # ['case', 'mes', 'quality_criteria', ...]
meta = client.get_meta() # {'version': ..., 'config': ..., 'scopes': [...]}
Scopes
| Scope | What it checks |
|---|---|
case |
Клинические рекомендации (КР) — general compliance |
mes |
Медико-экономический стандарт (МЭС) — OMS minimum coverage |
regional_standard |
Территориальная программа ОМС |
standard_of_care |
Федеральный стандарт оказания помощи (Приказ МЗ РФ) |
relevant_normative_acts |
Порядки оказания помощи (e.g. 3/14/7-day rule in oncology) |
quality_criteria |
Критерии оценки качества (КОК, Приказ №520н) |
dispensary_observation |
План диспансерного наблюдения |
Configuration
| Arg | Default | Env var |
|---|---|---|
api_key |
None |
NORTHLIGHT_API_KEY |
base_url |
https://api.sciencerocket.tech |
— |
timeout |
300 s |
— |
LLM-backed validation can take minutes, so timeouts default to five.
Logging
The SDK uses the standard logging module. Turn on INFO to see retry decisions:
import logging
logging.getLogger("northlight_checker").setLevel(logging.INFO)
Full API reference
See devs.sciencerocket.tech/docs for the complete API reference including all fields, scopes, and examples.
License
Apache 2.0. © ООО «Наука Ракета».
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 northlight_checker-0.1.0.tar.gz.
File metadata
- Download URL: northlight_checker-0.1.0.tar.gz
- Upload date:
- Size: 17.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 |
fc2aa6538c441db17e54d3d573d2c2f81fe19e6ca7a3c8ac082368df11f91686
|
|
| MD5 |
041773b74219edfe16020e891b58d397
|
|
| BLAKE2b-256 |
1371c86ca36c45578fd914fc93921ce612cd23d19c5b7b54c500724362f4a2c3
|
File details
Details for the file northlight_checker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: northlight_checker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.2 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 |
25ec7a0cb67adf6985a5569e4ddae5819062fba4c84444af503631a4415266fa
|
|
| MD5 |
c9091cc5020a7fdc190255cdba1fb063
|
|
| BLAKE2b-256 |
acc270a0da3c8bf454425b1abf95dae3f88d51a79469cd72356fea67c26f6f03
|