Skip to main content

HOPPR Python SDK

The HOPPR Python SDK allows you to interact with the HOPPR API for managing studies, adding images, and performing model inferences.

Installation

To install the HOPPR SDK, you can use pip:

pip install -U hopprai

This will install the HOPPR SDK along with its dependencies.

Initialization

To start using the HOPPR SDK, you need to initialize it with your API key:

Note: Do not place your API key directly in your code. Instead, use environment variables or other secure methods to manage your API key. This helps prevent accidental exposure of sensitive information.

import os
from hopprai import HOPPR

api_key = os.getenv("HOPPR_API_KEY")
hoppr = HOPPR(api_key)

Make sure to set the HOPPR_API_KEY environment variable with your actual API key.

Error Handling

To handle errors more effectively, the HOPPR SDK includes a custom HOPPRError type that provides the status code and an error message, allowing users to respond accordingly to specific error situations.

Here's an example of how to handle errors:

from hopprai import HOPPR

api_key = os.getenv("HOPPR_API_KEY")
hoppr = HOPPR(api_key)

try:
  study = hoppr.create_study("example_study_reference")
except Exception as e:
  print(f"Error occurred: Status code: {e.status_code}, Message: {e.message}")

Examples

Create a Study

To create a new study, use the create_study method:

reference = "example_study_reference"
study = hoppr.create_study(reference)
print(f"Created study with id: {study.id}")

Retrieve a Study

To retrieve an existing study by its id:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
study = hoppr.get_study(study_id)
if study:
  print(f"Study id: {study.id}, Reference: {study.reference}")
else:
  print("Study not found.")

Delete a Study

To delete a study by its id:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
if hoppr.delete_study(study_id):
  print("Study deleted successfully.")
else:
  print("Failed to delete study.")

Add an Image to a Study

To add an image to a study:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
reference = "1.2.840.113619.2.312.4120.793348.11111.1586342345.233"
image_data = open("path/to/your/image.dcm", "rb").read()

image = hoppr.add_study_image(study_id, reference, image_data)
print(f"Added image with id: {image.id}")

Delete an Image from a Study

To delete an image from a study:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
image_id = "1.2.840.113619.2.312.4120.793348.11111.1586342345.233"
if hoppr.delete_study_image(study_id, image_id):
  print("Image deleted successfully.")
else:
  print("Failed to delete image.")

Prompt a Model for Inference

To prompt a model for inference and wait for the response:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
model = "model"
prompt = "What findings are present in this study?"
organization = "your_org" # optional

response = hoppr.prompt_model(study_id=study_id, model=model, prompt=prompt, organization=organization)
if response:
  print(f"Model response: {response.response}")
else:
  print("Model inference timed out or failed.")

Prompt a Model for Inference Asynchronously

To prompt a model for inference asynchronously:

study_id = "a3f1d5c2-41d4-4c9a-8b8f-8e5f9a4e8f9a"
model = "model"
prompt = "What findings are present in this study?"
organization = "your_org" # optional

inference_id = hoppr.prompt_model_async(study_id=study_id, model=model, prompt=prompt, organization=organization)
print(f"Inference queued with id: {inference_id}")

To give a model prior studies, first attach each prior to the study and add its images:

prior = hoppr.add_prior_study(study_id, "prior_study_reference", report="Optional prior report text")
image = hoppr.add_prior_study_image(study_id, prior.id, "prior_image_reference", image_bytes)

Priors can also be updated or removed:

hoppr.update_prior_study(study_id, prior.id, report="Updated report text")
hoppr.delete_prior_study_image(study_id, prior.id, image.id)
hoppr.delete_prior_study(study_id, prior.id)

Models that accept extra inputs, such as prior studies, take them through additional_inputs. Each model defines its own schema, the payload is limited to 2 MB, and any report text is assumed to be de-identified. prompt_model accepts it as well:

inference_id = hoppr.prompt_model_async(
  study_id=study_id,
  model=model,
  additional_inputs={"prior_studies": [{"study_id": prior.id}]},
)

To retrieve the response later:

timeout = 180
response = hoppr.retrieve_prompt_response(study_id, inference_id, timeout)
if response:
  print(f"Model response: {response.response}")
else:
  print("Model inference timed out or failed.")

Download Inference Files

To download the result files of an inference as a zip archive:

hoppr.download_inference_files(study_id, inference_id, output_path="inference_results.zip")

The archive bytes are also returned, so output_path can be omitted.

Datasets and Training Jobs

List Datasets

To retrieve all datasets:

datasets = hoppr.get_datasets()
for ds in datasets:
  print(f"Dataset id: {ds['id']}, Name: {ds['name']}")

Retrieve a Dataset

To retrieve a dataset:

dataset_id = "your_dataset_id"
dataset = hoppr.get_dataset(dataset_id)
print(f"Dataset: {dataset}")

Create a Dataset

To create a new dataset (expects a .jsonl file):

dataset_name = "my_dataset"
description = "A test dataset."
file_path = "path/to/dataset.jsonl"
dataset = hoppr.create_dataset(dataset_name, description, file_path)
print(f"Created dataset with id: {dataset['id']}")

Create a Training Job

To create a new training job:

training_job = {
  "dataset_id": "your_dataset_id",
  "model": "hoppr_model:1.0.0",
  # Add other required fields as needed
}
job = hoppr.create_training_job(training_job)
print(f"Created training job with id: {job['id']}")

Retrieve a Training Job

To get the status or details of a training job:

training_job_id = "your_training_job_id"
job = hoppr.get_training_job(training_job_id)
print(f"Training job status: {job['status']}")

Cancel a Training Job

To cancel a running training job:

training_job_id = "your_training_job_id"
result = hoppr.cancel_training_job(training_job_id)
print(f"Cancel result: {result}")

Download Training Manifest

To download the training/validation manifest for a training job:

training_job_id = "your_training_job_id"
csv_content = hoppr.download_training_manifest(training_job_id)
print(csv_content)

To save it directly to a file:

hoppr.download_training_manifest(training_job_id, output_path="manifest.csv")

The manifest CSV contains one row per image with columns: study_id, series_id, instance_id, classification, and train/val.

Map Manifest IDs to Original Identifiers

After downloading a manifest, use map_manifest_ids to replace HOPPR de-identified IDs with your original DICOM identifiers. This runs entirely on your local machine — no data is sent to HOPPR.

result = hoppr.map_manifest_ids(
  manifest_path="manifest.csv",
  jsonl_path="path/to/your/dataset.jsonl",
  organization="your_organization",
)
print(result)

To write the remapped manifest to a file:

hoppr.map_manifest_ids(
  manifest_path="manifest.csv",
  jsonl_path="path/to/your/dataset.jsonl",
  organization="your_organization",
  output_path="remapped_manifest.csv",
)

The jsonl_path should point to the original JSONL file you uploaded when creating the dataset. Each row must contain one of StudyInstanceUID, SeriesInstanceUID, or SOPInstanceUID as the identifier key.

Metadata

Release files for hopprai 2026.44.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hopprai 2026.44.1
File Size Uploaded Provenance Actions
hopprai-2026.44.1.tar.gz 9.7 kB Without provenance Details for hopprai-2026.44.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hopprai 2026.44.1
File Interpreter ABI Platform Actions
hopprai-2026.44.1-py3-none-any.whl Python 3 none any Details for hopprai-2026.44.1-py3-none-any.whl

Total release size: 20.1 kB

Release files / hopprai-2026.44.1.tar.gz

Download URL hopprai-2026.44.1.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
522a0d759c9b49af2a1ab9343812997fe25a4c22266b7291e301f349c9344cd4
BLAKE2b-256 checksum
How to use checksums
6264d9148d84e0bfe6541ddfeb65b279a77273a2ff50adf79c88a30238c5aaf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / hopprai-2026.44.1-py3-none-any.whl

Download URL hopprai-2026.44.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af7da86fb74e99462c5d4250e9149c6eade7846fd1ce9579057d7a762e5495be
BLAKE2b-256 checksum
How to use checksums
2c03d745bcc2a18f813fb60dc288231f1adc678e8a6d0e09fdc8734609e5d9a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for hopprai 2026.44.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page