Skip to main content

Biolevate SDK - High-level Python SDK for the Biolevate API

Project description

Biolevate Python SDK

PyPI Python Coverage CI

Python SDK for the Biolevate API — the core REST API for the Elise platform. Connect to your storage backends, index documents with AI, organise collections, and run Question Answering or Extraction jobs.

Installation

pip install biolevate

Requires Python 3.11+.

Authentication

The Biolevate API uses Bearer token authentication via a Personal Access Token (PAT). Tokens are provided by Biolevate upon request. Self-service token management through the Elise admin portal is coming soon.

from biolevate import BiolevateClient

client = BiolevateClient(
    base_url="https://<your-elise-domain>",
    token="<your-pat>",
)

The client can also be used as an async context manager:

async with BiolevateClient(base_url="...", token="...") as client:
    providers = await client.providers.list()

Quick Start

import asyncio
from biolevate import BiolevateClient

async def main():
    async with BiolevateClient(base_url="https://<your-elise-domain>", token="<your-pat>") as client:
        providers = await client.providers.list()
        for provider in providers.data:
            print(provider.name, provider.type_)

asyncio.run(main())

Resources

Providers

Browse the storage backends connected to your Elise instance. Providers are configured through the admin UI and are read-only from the API.

page = await client.providers.list(page=0, page_size=20, query="s3")
print(f"{page.total_elements} providers found")

for provider in page.data:
    print(provider.id.id)   # UUID used in subsequent calls
    print(provider.name)
    print(provider.type_)   # S3, AZURE, GCS, LOCAL, ...

provider = await client.providers.get("uuid-here")

Provider Items

Manage files and folders within a provider's storage backend.

# List items at a path
items = await client.provider_items.list(provider_id="uuid", key="path/to/folder/")

# Upload a file
with open("report.pdf", "rb") as f:
    item = await client.provider_items.upload(
        provider_id="uuid",
        key="reports/report.pdf",
        content=f.read(),
        content_type="application/pdf",
    )

# Create a folder
folder = await client.provider_items.create_folder(provider_id="uuid", key="reports/2024/")

# Get a pre-signed download URL
url = await client.provider_items.get_download_url(provider_id="uuid", key="reports/report.pdf")

# Delete an item
await client.provider_items.delete(provider_id="uuid", key="reports/old-report.pdf")

Files

Index a provider item as an EliseFile to make it available for AI-powered analysis.

# Index a file (triggers AI analysis)
file = await client.files.create(
    provider_id="provider-uuid",
    key="reports/report.pdf",
)
print(file.id.id)  # UUID of the indexed EliseFile

# Get an indexed file
file = await client.files.get("file-uuid")

# List indexed files
page = await client.files.list(provider_id="provider-uuid", page=0, page_size=20)

# Trigger reindexing after the source file changes
await client.files.reindex("file-uuid")

# Delete the indexed file (does not delete the source from storage)
await client.files.delete("file-uuid")

Collections

Organise indexed files into named collections for structured workflows.

# Create a collection
collection = await client.collections.create(name="Q4 Reports", description="All Q4 2024 reports")

# List collections
page = await client.collections.list(query="Q4")

# Add/remove files
await client.collections.add_file(collection_id=collection.id.id, file_id="file-uuid")
await client.collections.remove_file(collection_id=collection.id.id, file_id="file-uuid")

# List files in a collection
files = await client.collections.list_files(collection_id=collection.id.id)

# Update or delete
await client.collections.update(collection_id=collection.id.id, name="Q4 Reports 2024")
await client.collections.delete(collection_id=collection.id.id)

Question Answering

Ask natural-language questions about indexed documents. Jobs run asynchronously — submit, poll until complete, then retrieve results.

from biolevate import QuestionInput

job = await client.question_answering.create_job(
    file_ids=["file-uuid-1", "file-uuid-2"],
    collection_ids=[],
    questions=[
        QuestionInput(
            id="q1",
            question="What is the main conclusion of this document?",
            answer_type={"dataType": "STRING", "multiValued": False},
        ),
        QuestionInput(
            id="q2",
            question="What is the publication date?",
            answer_type={"dataType": "DATE", "multiValued": False},
        ),
    ],
)

# Poll until complete
import asyncio
while True:
    status = await client.question_answering.get_job(job.id.id)
    if status.status in ("SUCCESS", "FAILED"):
        break
    await asyncio.sleep(2)

# Retrieve answers
results = await client.question_answering.get_job_outputs(job.id.id)
for result in results:
    print(result.question, "->", result.raw_value)
    print("Source:", result.explanation)

# Retrieve source annotations (passages used by the AI)
annotations = await client.question_answering.get_job_annotations(job.id.id)

Extraction

Extract typed metadata fields from indexed documents. The AI extracts structured values based on field definitions you provide.

from biolevate import MetaInput

job = await client.extraction.create_job(
    file_ids=["file-uuid"],
    collection_ids=[],
    metas=[
        MetaInput(
            meta="document_title",
            description="The full title of the document",
            answer_type={"dataType": "STRING", "multiValued": False},
        ),
        MetaInput(
            meta="study_year",
            description="The year the study was conducted or published",
            answer_type={"dataType": "INT", "multiValued": False},
        ),
        MetaInput(
            meta="risk_level",
            description="The assessed risk level",
            answer_type={"dataType": "ENUM", "multiValued": False, "enumValues": ["LOW", "MEDIUM", "HIGH"]},
        ),
    ],
)

# Poll until complete
import asyncio
while True:
    status = await client.extraction.get_job(job.id.id)
    if status.status in ("SUCCESS", "FAILED"):
        break
    await asyncio.sleep(2)

# Retrieve extracted values
results = await client.extraction.get_job_outputs(job.id.id)
for result in results:
    print(result.meta, "->", result.answer)
    print("Explanation:", result.explanation)

Error Handling

from biolevate import BiolevateClient, NotFoundError, AuthenticationError, APIError, BiolevateError

try:
    file = await client.files.get("unknown-uuid")
except NotFoundError:
    print("File not found")
except AuthenticationError:
    print("Invalid token or insufficient permissions")
except APIError as e:
    print(f"API error {e.status_code}: {e.message}")
except BiolevateError:
    print("Unexpected SDK error")
Exception HTTP status When raised
AuthenticationError 401, 403 Invalid token or insufficient permissions
NotFoundError 404 Resource does not exist
APIError Any other 4xx/5xx Unexpected API error
BiolevateError Base class for all SDK exceptions

Development

# Install with dev dependencies
cd python && uv sync --all-extras

# Run unit tests
uv run pytest sdk/tests/unit -v

# Run integration tests (requires a live Elise instance)
BIOLEVATE_API_URL=https://<your-elise-domain> BIOLEVATE_TOKEN=<your-pat> \
  uv run pytest sdk/tests/integration -v

# Lint and format
uv run ruff check sdk/
uv run ruff format sdk/

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

biolevate-0.3.1.tar.gz (39.8 kB view details)

Uploaded Source

Built Distribution

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

biolevate-0.3.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file biolevate-0.3.1.tar.gz.

File metadata

  • Download URL: biolevate-0.3.1.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for biolevate-0.3.1.tar.gz
Algorithm Hash digest
SHA256 3c039a086e47cdd7c97560b4d0c3f3a0cbce9d50086478b637c739bc415a9054
MD5 8facd9749d9feacf1247f8a476d0f720
BLAKE2b-256 94017b32b4cd2294c25471621dfc50014b99e09f0d9587ebff25bf30ec0679a0

See more details on using hashes here.

File details

Details for the file biolevate-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: biolevate-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for biolevate-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7e222c45f9753b9c39da9d655d7ccf7edcf5d396443afcf982e8ddd058455df
MD5 a8dffc66873dcb1bd3dd628879f080e7
BLAKE2b-256 8f1c908ad668bc99b9d8899ad2a14b9ff453e56220540e2f28602baac88ee610

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