Skip to main content

Python SDK for NessyAPI — Clinical Decision Support API

Project description

NessyAPI Python SDK

Python SDK for NessyAPI — Clinical Decision Support API.

Install

pip install nessyapi-sdk

Quick Start

from nessyapi_sdk import NessyClient

with NessyClient(api_key="nsy_live_...") as client:
    # Create a session for a patient
    session = client.create_session(
        chief_complaint="headache",
        age=35,
        sex="male",
        patient_id="your-patient-123",  # links to patient profile
    )

    # Answer questions from the engine
    q = session.current_question
    while q:
        print(f"Q: {q.text}")
        
        # Send patient's answer (NLP extracts medical fields automatically)
        result = client.answer(session.session_id, q.question_id, raw_text="3 days, getting worse")
        
        if result.is_complete:
            break
        q = result.current_question

    # Get final results
    results = client.finalize(session.session_id)
    print(f"Triage: {results.triage_level}")
    for dx in results.differentials:
        print(f"  {dx.diagnosis} ({dx.probability:.0%}) — ICD-10: {dx.icd10}")

One-Line Assessment

results = client.run_assessment("chest_pain", age=55, sex="male")
print(results.triage_level)  # "urgent"
print(results.differentials[0].diagnosis)  # "Acute Coronary Syndrome"

Async Support

from nessyapi_sdk import AsyncNessyClient

async with AsyncNessyClient(api_key="nsy_live_...") as client:
    session = await client.create_session("headache", age=35, sex="male")
    results = await client.run_assessment("fever", age=28, sex="female")

Session Management

# List all sessions
sessions = client.list_sessions(status="finalized", limit=10)
print(f"Total: {sessions.total}")

# Get questions with progress
questions = client.get_questions(session_id)
print(f"Progress: {questions.questions_asked}/{questions.questions_total}")

# Export complete session record
export = client.export_session(session_id)

# Update demographics after creation
client.update_demographics(session_id, age=42, sex="female")

# Submit feedback on diagnosis accuracy
client.submit_feedback(session_id, "correct", notes="Confirmed by specialist")

Patient Profiles

# Create/update patient profile (data persists across sessions)
client.update_patient("patient-123",
    chronic_conditions=["diabetes", "hypertension"],
    current_medications=["metformin", "lisinopril"],
    allergies=["penicillin"],
)

# Get patient profile
profile = client.get_patient("patient-123")

# Get aggregated patient epicrisis (summary of all sessions)
summary = client.get_patient_summary("patient-123")

# List patient's sessions
sessions = client.list_patient_sessions("patient-123")

Admin & Billing

# Token balance
balance = client.get_balance()
print(f"Remaining: {balance.balance} tokens ({balance.tier} tier)")

# Usage stats
usage = client.get_usage(days=30)
print(f"Used: {usage.total_tokens} tokens")

# Rate limit status
rl = client.get_rate_limit()
print(f"Requests: {rl['requests_used']}/{rl['rate_limit_rpm']} RPM")

# Tenant statistics
stats = client.get_stats()

# API key management
keys = client.list_keys()
new_key = client.create_key("production-server")
client.revoke_key(key_id)

Webhook Verification

from nessyapi_sdk import verify_webhook_signature

# In your webhook handler (Flask example):
@app.post("/webhooks/nessy")
def handle_webhook():
    is_valid = verify_webhook_signature(
        payload=request.data,
        secret="whsec_...",
        signature=request.headers["X-NessyAPI-Signature-256"],
        timestamp=request.headers["X-NessyAPI-Timestamp"],  # always pass this
    )
    if not is_valid:
        abort(403)
    
    event = request.json
    if event["event_type"] == "assessment.completed":
        # Process completed assessment
        print(f"Triage: {event['data']['triage_level']}")

Error Handling

from nessyapi_sdk import NessyClient, NessyAPIError

try:
    results = client.finalize("invalid-session-id")
except NessyAPIError as e:
    print(e.status)    # 404
    print(e.detail)    # "Session not found"
    print(e.error_code)  # "not_found"

Token Costs

Method Cost
create_session() 1 token
route() 5 tokens
answer() 8 tokens
answer(skip=True) 0 tokens
get_results() FREE
get_state() FREE
finalize() FREE
get_questions() FREE
All admin/patient methods FREE

Features

  • Sync and async clients
  • Typed response models (dataclasses with .raw dict access)
  • Automatic retry with exponential backoff (429, 5xx)
  • HTTPS enforcement
  • ID validation (prevents path traversal)
  • Webhook signature verification with replay protection

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nessyapi_sdk-0.3.2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nessyapi_sdk-0.3.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file nessyapi_sdk-0.3.2.tar.gz.

File metadata

  • Download URL: nessyapi_sdk-0.3.2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for nessyapi_sdk-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c9b3361a9c653dd4636449e25f143d4bb2ae391b954c138dab840b22a3db9b29
MD5 8b1650f14469640c22e96f5a23e6c54d
BLAKE2b-256 f0bbb31eed93abb97f9445110405e54571172c2373f930116247002fc820f74c

See more details on using hashes here.

File details

Details for the file nessyapi_sdk-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: nessyapi_sdk-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for nessyapi_sdk-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 24cf6703e7b638829b2f6cae37b4ba3511bab994fb7a8dbb881bf1e16f006afb
MD5 bf6afbba8d883d3e8322f2848cb2ef5b
BLAKE2b-256 0ef2f59bc730e343cd0a76489ec3974be013d79c07dc5ae2943ea31680895eb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page