Python SDK
The Telesoft Healthcare AI Python SDK makes it easy to integrate our medical AI capabilities into your Python applications. This SDK simplifies authentication, request handling, and response parsing so you can focus on building your healthcare solutions.
Installation
Install the SDK using pip:
pip install telesoft-healthcare-ai
The SDK requires Python 3.7 or later.
Getting Started
To use the SDK, you'll need an API key from the Telesoft Developer Portal:
Authentication
import os
from telesoft import TelesoftAI
# Initialize the client with your API key
telesoft = TelesoftAI(api_key="YOUR_API_KEY")
# Or use an environment variable (recommended)
telesoft = TelesoftAI(api_key=os.environ.get("TELESOFT_API_KEY"))
⚠️ API Key Security
Never hardcode your API key directly in your source code. Use environment variables or a secure configuration management system.
Basic Usage
Here's a simple example of using the SDK to analyze patient symptoms:
import os
from telesoft import TelesoftAI
# Initialize the client
telesoft = TelesoftAI(api_key=os.environ.get("TELESOFT_API_KEY"))
# Analyze patient symptoms
def analyze_patient_symptoms():
analysis = telesoft.diagnostics.analyze(
patient_data={
"age": 45,
"sex": "female",
"symptoms": ["cough", "fever", "shortness of breath"],
"duration": "5 days",
"medical_history": ["hypertension", "type 2 diabetes"],
"medications": ["lisinopril", "metformin"]
},
options={
"include_confidence_scores": True,
"include_differential_diagnosis": True,
"include_recommendations": True,
"include_evidence": True
}
)
# Access the results
print(f"Primary diagnosis: {analysis.primary_diagnosis.condition}")
print(f"Confidence: {analysis.primary_diagnosis.confidence_score:.2f}")
print("\nDifferential diagnoses:")
for diagnosis in analysis.differential_diagnoses:
print(f"- {diagnosis.condition} ({diagnosis.confidence_score:.2f})")
print("\nRecommended tests:")
for test in analysis.recommendations.diagnostic_tests:
print(f"- {test.name}: {test.rationale}")
return analysis
# Run the analysis
if __name__ == "__main__":
try:
analyze_patient_symptoms()
except Exception as e:
print(f"Error: {e}")
Key Features
Diagnostic Analysis
Analyze patient symptoms, medical history, and demographics to generate diagnostic insights.
Medical Imaging Analysis
Analyze various medical images including X-rays, CT scans, MRIs, and more.
Treatment Recommendations
Generate evidence-based treatment recommendations based on patient data.
Medical Document Processing
Extract structured information from medical documents, reports, and notes.
Advanced Examples
Analyzing Medical Images
import os
from telesoft import TelesoftAI
# Initialize the client
telesoft = TelesoftAI(api_key=os.environ.get("TELESOFT_API_KEY"))
# Analyze a chest X-ray image
def analyze_chest_xray(image_path):
with open(image_path, "rb") as image_file:
analysis = telesoft.imaging.analyze(
imaging_type="chest-xray",
image=image_file,
options={
"include_annotations": True,
"include_heatmap": True,
"confidence_threshold": 0.5
}
)
print(f"Found {len(analysis.findings)} findings:")
for finding in analysis.findings:
print(f"- {finding.description} (confidence: {finding.confidence:.2f})")
print(f" Location: {finding.location}")
# Save the annotated image if provided
if analysis.annotated_image:
with open("annotated_xray.png", "wb") as f:
f.write(analysis.annotated_image)
print("Annotated image saved as annotated_xray.png")
return analysis
# Example usage
if __name__ == "__main__":
analyze_chest_xray("path/to/chest_xray.dcm")
Using with Flask
import os
from flask import Flask, request, jsonify
from telesoft import TelesoftAI
from telesoft.exceptions import TelesoftError
app = Flask(__name__)
# Initialize the Telesoft client
telesoft = TelesoftAI(api_key=os.environ.get("TELESOFT_API_KEY"))
@app.route('/api/analyze', methods=['POST'])
def analyze_symptoms():
try:
# Get patient data from request
patient_data = request.json.get('patient_data')
if not patient_data:
return jsonify({"error": "Missing patient_data"}), 400
# Validate required fields
if not all(k in patient_data for k in ["age", "sex", "symptoms"]):
return jsonify({"error": "Missing required fields in patient_data"}), 400
# Call Telesoft API
analysis = telesoft.diagnostics.analyze(
patient_data=patient_data,
options={
"include_confidence_scores": True,
"include_differential_diagnosis": True,
"include_recommendations": True
}
)
# Convert to serializable format
result = {
"primary_diagnosis": {
"condition": analysis.primary_diagnosis.condition,
"confidence_score": analysis.primary_diagnosis.confidence_score
},
"differential_diagnoses": [
{
"condition": d.condition,
"confidence_score": d.confidence_score
}
for d in analysis.differential_diagnoses
],
"recommendations": {
"diagnostic_tests": [
{
"name": t.name,
"rationale": t.rationale
}
for t in analysis.recommendations.diagnostic_tests
]
}
}
return jsonify(result)
except TelesoftError as e:
# Handle Telesoft API errors
return jsonify({"error": str(e)}), 400
except Exception as e:
# Handle unexpected errors
app.logger.error(f"Unexpected error: {e}")
return jsonify({"error": "Internal server error"}), 500
if __name__ == '__main__':
app.run(debug=True)