Skip to main content

Python SDK for the Diaphora API

Project description

Diaphora Python SDK

Python client library for the Diaphora API.

Supported Python versions: 3.11, 3.12, 3.13

Installation

pip install diaphora-python

Authentication

The Diaphora client needs your Diaphora credentials. You can either pass these directly to the constructor or via environment variables.

from diaphora.auth.basic_authenticator import BasicAuthenticator

auth = BasicAuthenticator("user@example.com", "your-password")

To use a custom auth scheme, implement DiaphoraAuthenticator:

from diaphora.auth.authenticator_interface import DiaphoraAuthenticator

class MyAuthenticator(DiaphoraAuthenticator):
    def token(self) -> str:
        return "my-session-token"

Diaphora

from diaphora import Diaphora

sdk = Diaphora(authenticator)
Attribute Description
sdk.store Plan and result management
sdk.router Plan execution and MCP tools

Quickstart

Search for plans

from diaphora.models import SearchPlansNamespace

#Namespace is one of ALL, DIAPHORA, BARNDOOR, NONE
plans = sdk.store.search_plans(namespace=SearchPlansNamespace.DIAPHORA)

Showing Plan

plan = sdk.store.show_plan(str(plans[0].id))
print(plan.name, plan.description)

Create a plan

from diaphora.models import PlanRequest, PlanRequestVisibility

new_plan = sdk.store.create_plan(PlanRequest(
    name="Daily Summary",
    description="Summarises activity from the past 24 hours",
    visibility=PlanRequestVisibility.ORGANIZATION,
    labels=["summary", "daily"],
    text="<plan definition>",
))

Search results for a plan

from diaphora.models import SearchResultsStatus

results = sdk.store.search_results(
    plan_id=str(plan.id),
    status=SearchResultsStatus.SUCCESS,
)

Run a plan

response = sdk.router.run_plan(
    plan_id=str(plan.id),
    parameters={"animal_type": "feline"},
)

Stream a plan execution

handle_event is a function that can be defined with a custom implementation. The function here is just an example function for printing the contents of the streamed data

from diaphora.events import START_PHASE, END_PHASE, RESULT_PHASE, StreamEvent


def handle_event(event: StreamEvent):
    if event.event == START_PHASE:
        print(f"[{event.component}] starting {event.session}...")
    elif event.event == END_PHASE:
        print(f"[{event.component}] done")
    elif event.event == RESULT_PHASE:
        print(event.content["document"])

sdk.router.stream_plan(
    plan_id=str(plan.id),
    on_event=handle_event,
    parameters={"animal_type": "feline"},
)

sdk.store

Plans

Method Description
search_plans(label, search, namespace, limit, offset) Search plans. namespace is one of ALL, DIAPHORA, BARNDOOR, NONE
show_plan(plan_id) Get plan details
create_plan(body: PlanRequest) Create a plan
update_plan(plan_id, body: PlanRequest) Update a plan
delete_plan(plan_id) Delete a plan
list_plan_labels() List all labels used across plans

Results

Method Description
search_results(search, status, limit, offset, start, end, plan_id) Search results. status is SUCCESS or ERROR
show_results(results_id) Get result details
delete_results(results_id) Delete a result
list_results_stats(start, end) Get result statistics

Public Links

Method Description
list_public_links(results_id) List public links for a result
create_public_link(results_id, body: PublicLinkRequest) Create a public link. expires_in accepts values like "7d" or "24h"
delete_public_link(results_id, public_link_id) Delete a public link
show_result_public_link(public_link_id) Fetch a result via public link (no auth required)

Tools & Schema

Method Description
list_tools() List available tools
show_tools(tool_id) Get tool details
show_default_tools() Get default tools
get_frags_schema() Get the Frags JSON schema

sdk.router

Plan Execution

Method Description
run_plan(plan_id, parameters) Execute a plan synchronously
stream_plan(plan_id, on_event, parameters) Execute a plan and receive SSE events via callback

stream_plan delivers StreamEvent objects to the callback:

event.event Additional fields Description
START_PHASE component, session A component started
END_PHASE component A component finished
RESULT_PHASE content Result payload — content["document"] holds the output text

MCP Tools

Method Description
check_plan_mcp_requirements(plan_id) Check which MCP servers a plan needs and their auth status
refresh_plan_mcp_requirements(plan_id) Force-refresh MCP requirement status
check_tool_mcp_requirements() Check global MCP requirements
list_tool_commands(tools_id, server_id) List commands on an MCP server
call_tool_command(tools_id, server_id, command_name) Execute an MCP command
list_mcp_auth_cache() List cached MCP OAuth tokens
delete_mcp_auth_cache(cache_id) Revoke a cached MCP token
mcp_callback(state, code) Handle an OAuth redirect callback
render_template(body: RenderTemplate) Render a template

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

diaphora_python-0.1.0.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

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

diaphora_python-0.1.0-py3-none-any.whl (79.0 kB view details)

Uploaded Python 3

File details

Details for the file diaphora_python-0.1.0.tar.gz.

File metadata

  • Download URL: diaphora_python-0.1.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for diaphora_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 512f6d25497317eb32ee5da7d4b5c0fb8be6cf86bc5f5bce2a8368bdc9c88c90
MD5 a4485b8dc69ed5ff90ac5becc669ab42
BLAKE2b-256 318d1824681e5d8b3083be847bf7475a7861776f42ad30f84e54bb6f393d7764

See more details on using hashes here.

Provenance

The following attestation bundles were made for diaphora_python-0.1.0.tar.gz:

Publisher: publish-to-pypi.yml on diaphora-ai/diaphora-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diaphora_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: diaphora_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 79.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for diaphora_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf6631beef81ca1be1e3757207360e8cf64bc47c374ff7e5a34c2e7777b72057
MD5 ebe599b9dc00ee6fbb7df3ac21c1edc6
BLAKE2b-256 622bcec8a995b333fb303c12061fabd47ab15ef6cbc1a7614b21f22fe04abdef

See more details on using hashes here.

Provenance

The following attestation bundles were made for diaphora_python-0.1.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on diaphora-ai/diaphora-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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