Skip to main content

Official Python SDK for Frekil API

Project description

Frekil SDK

The official Python SDK for the Frekil API.

Installation

pip install frekil

Usage

Authentication

To use the SDK, you'll need an API key from your Frekil account:

from frekil import FrekilClient

# Initialize the client with your API key
client = FrekilClient(api_key="your-api-key")

# Optionally specify a custom base URL (e.g., for development)
client = FrekilClient(
    api_key="your-api-key",
    base_url="https://dev.notatehq.com/api/sdk"
)

Working with Projects

List Projects

Get all projects the authenticated user has access to:

# Get all projects
projects = client.projects.list()

# Example response:
# [
#     {
#         "id": "uuid",
#         "name": "Project Name",
#         "description": "Project Description",
#         "role": "ADMIN",  # User's role in the project
#         "created_at": "2024-03-21T10:00:00Z",
#         "updated_at": "2024-03-21T10:00:00Z",
#         "is_ct_scan": true,
#         "tags": ["tag1", "tag2"]
#     },
#     ...
# ]

Get Project Membership

Get membership details for a specific project including user roles and status:

# Get project membership
project_id = "project-uuid"
memberships = client.projects.get_membership(project_id)

# Example response:
# [
#     {
#         "user_id": "uuid",
#         "email": "user@example.com",
#         "name": "User Name",  # Full name or email if name not set
#         "role": "ADMIN",      # User's role in the project
#         "percentage": 100,    # User's allocation percentage
#         "is_active": true,    # Whether the user is active
#         "is_project_admin": true,  # Whether user is project admin
#         "created_at": "2024-03-21T10:00:00Z",
#         "updated_at": "2024-03-21T10:00:00Z"
#     },
#     ...
# ]

Get Project Images

Get all images in a project:

# Get project images
project_id = "project-uuid"
images = client.projects.get_images(project_id)

# Example response:
# [
#     {
#         "id": "images/image1.dcm",  # Full image key
#         "filename": "image1.dcm",   # Just the filename
#         "created_at": "2024-03-21T10:00:00Z",
#         "updated_at": "2024-03-21T10:00:00Z"
#     },
#     ...
# ]

Get Project Allocations

Get all allocations in a project, including user roles for both annotators and reviewers:

# Get project allocations
project_id = "project-uuid"
allocations = client.projects.get_allocations(project_id)

# Example response:
# [
#     {
#         "allocation_id": "uuid",
#         "image_id": "images/image1.dcm",  # Full image key
#         "image_filename": "image1.dcm",   # Just the filename
#         "annotator_email": "annotator@example.com",  # May be null
#         "reviewer_email": "reviewer@example.com",    # May be null
#         "status": "PENDING",  # One of: PENDING, PENDING_REVIEW, APPROVED, REJECTED
#         "created_at": "2024-03-21T10:00:00Z",
#         "is_ground_truth": false
#     },
#     ...
# ]

Bulk Allocate Images

Allocate images to specific annotators and reviewers:

# Allocate images to specific annotators and reviewers
project_id = "project-uuid"
allocations = [
    {
        "image_key": "images/image1.dcm",  # Full image key
        "annotators": ["annotator1@example.com", "annotator2@example.com"],
        "reviewers": ["reviewer1@example.com", "reviewer2@example.com"]
    },
    {
        "image_key": "images/image2.dcm",
        "annotators": ["annotator1@example.com"],
        "reviewers": ["reviewer1@example.com"]
    }
]

# Set override_existing_work=True to override allocations even if work has been done
result = client.projects.bulk_allocate_images(
    project_id=project_id,
    allocations=allocations,
    override_existing_work=False
)

# Example success response:
# {
#     "status": "success",
#     "message": "Successfully processed allocations",
#     "created_count": 5,      # Number of new allocations created
#     "updated_count": 2,      # Number of existing allocations updated
#     "overridden_count": 1,   # Number of allocations with work that were overridden
#     "total_allocations": 8,  # Total number of allocations processed
#     "override_used": true    # Whether override_existing_work was used
# }

# Example validation error response:
# {
#     "status": "validation_failed",
#     "errors": ["Missing image_key in allocation 1"],
#     "invalid_users": [
#         {
#             "email": "user@example.com",
#             "role": "annotator",
#             "reason": "User is not a project member with annotator role",
#             "allocation_index": 1,
#             "image_key": "image1.dcm"
#         }
#     ],
#     "existing_work": [
#         {
#             "image_key": "image1.dcm",
#             "annotator": "annotator@example.com",
#             "reviewer": "reviewer@example.com",
#             "allocation_index": 1,
#             "existing_work": [
#                 {
#                     "type": "annotation",
#                     "user": "annotator@example.com",
#                     "created_at": "2024-03-21T10:00:00Z",
#                     "status": "completed"
#                 }
#             ],
#             "message": "Cannot modify allocation as work has already been done",
#             "can_override": true
#         }
#     ],
#     "message": "Please fix the following issues before proceeding:",
#     "instructions": {
#         "invalid_users": "Ensure all users exist and have the correct project role",
#         "existing_work": "Cannot modify allocations where work has already been done. Use override_existing_work=true to force changes.",
#         "errors": "Fix any missing or invalid data in the request"
#     },
#     "override_available": true,
#     "override_instructions": "To override existing work, set override_existing_work=true in the request body"
# }

Error Handling

The SDK uses custom exception classes to handle API errors:

from frekil.exceptions import FrekilAPIError, FrekilClientError

try:
    projects = client.projects.list()
except FrekilClientError as e:
    # Handle client errors (e.g., authentication issues, invalid parameters)
    print(f"Client error: {e} (Status: {e.status_code})")
    print(f"Error details: {e.error_details}")
except FrekilAPIError as e:
    # Handle API errors (e.g., server issues)
    print(f"API error: {e} (Status: {e.status_code})")
    print(f"Error details: {e.error_details}")

Development

Setup

# Clone the repository
git clone https://github.com/notatehq/frekil-python-sdk.git
cd frekil-python-sdk

# Install dependencies
pip install -e ".[dev]"

Testing

pytest

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

frekil-0.1.6.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

frekil-0.1.6-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file frekil-0.1.6.tar.gz.

File metadata

  • Download URL: frekil-0.1.6.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for frekil-0.1.6.tar.gz
Algorithm Hash digest
SHA256 2c0de40f6cd10380ec9385fa6d07e8926b949ce36cb663c915aefb759fa0edf3
MD5 70fb911bcfe5aba6f4b84b18e9103290
BLAKE2b-256 f347ea6283ed47cdc8bda7f86b602630d2eeb52085a63f8b07ee7b751d68c1c5

See more details on using hashes here.

File details

Details for the file frekil-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: frekil-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for frekil-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2e0d1af79ca06864a1f98cf3eab6c3caf1f8156c1fb324a675c02ddd828bdf2c
MD5 f91673f5968fe2a048e5c8f3789c6c59
BLAKE2b-256 16241943f6c07f70d54e049c5fa1e7fccbd6c51dd878c5a7e02836462efb5bca

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