Metadata-Version: 2.4
Name: sectra-image-analysis-api
Version: 1.5.1
Summary: A wrapper for the Sectra Image Analysis API.
Project-URL: Homepage, https://github.com/amspath/sectra-image-analysis-api
Project-URL: Repository, https://github.com/amspath/sectra-image-analysis-api
Author-email: Robin van Hoorn <r.d.vanhoorn@amsterdamumc.nl>
License: MIT License
        
        Copyright (c) [year] [fullname]
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: WSI,digital pathology,medical imaging,whole slide image
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.11
Requires-Dist: hl7>=0.4.5
Requires-Dist: pillow>=10.0.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: requests-toolbelt>=1.0.0
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: fastapi[standard]>=0.115.0; extra == 'dev'
Requires-Dist: honcho>=2.0.0; extra == 'dev'
Requires-Dist: ruff>=0.12.5; extra == 'dev'
Requires-Dist: ty>=0.0.10; extra == 'dev'
Requires-Dist: types-requests>=2.32.4; extra == 'dev'
Description-Content-Type: text/markdown

# Python Client for Sectra

This python package aims to facilite the development of AI applications for Sectra PACS.

## Version
The library currently supports functionality up to do version 3.4 (Dec 2023). However, we will update to 5.0 in Juli, after which this library will be adjusted to the newest version as well. 

## Installation

To install sectra_client:
```
pip install sectra-image-analysis-api
```

## Usage

Before using the client, make sure you have access to a valid authentication token, and url, sent in the analysis requests.

### Example 1: Retrieve image information

```python
from sectra_client import SectraClient

# Info, sent by Sectra in the request
callback_url = "http://sectraweb.*.*.*/SectraPathologyServer/external/imageanalysis/v1"
callback_token = "abcde"
slide_id = "fghij"

# Use the context manager
with SectraClient(
    url=callback_url,
    token=callback_token
) as client:
    # Returns the image info with extended and personal health information data
    image_info = client.get_image_metadata(slide_id, extended=True, phi=True)
```

### Example 2: Download WSI
```python
from sectra_client import SectraClient

# Info, sent by Sectra in the request
...

# Use the context manager
with SectraClient(
    url=callback_url,
    token=callback_token
) as client:
    # Download the file(s) to an output directory, and returns the file paths of the file(s). 
    file_paths = client.download_slide_files(slide_id, output_dir="./path/to/output/dir/")
```

### Example 3: Without context manager
It is also possible to use the SectraClient without the context manager
```python
from sectra_client import SectraClient

# Info, sent by Setra in the request
...

# Open context manager
client = SectraClient(url=callback_url, token=callback_token)

# Perform API interactions
image_info = client.get_image_metadata(slide_id, extended=True, phi=False)

# Make sure to close the connection
client.close()
```

## Local development with the mock server
`MockSectraServer` simulates a Sectra PACS instance in memory so you can develop and test without a real server.

```python
from sectra_client.mock_server import MockSectraServer

server = MockSectraServer(token="dev-token")
with server.run(port=8001):
    server.trigger(
        webhook_url="http://localhost:8000/sectra/hook",
        application_id="my-app",
        slide_id="slide-001",
    )
    results = server.get_results(app_id="my-app", slide_id="slide-001")
```

See `examples/local_dev.py` for a complete round-trip: both servers started from a single script, a fake invocation fired, and results read back.
