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.5.tar.gz (47.0 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.5-py3-none-any.whl (79.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: diaphora_python-0.1.5.tar.gz
  • Upload date:
  • Size: 47.0 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.5.tar.gz
Algorithm Hash digest
SHA256 2179c42e36a81d638f53d809b5ee2cefb5c37622a93cbb4f8bea0cd7b12da507
MD5 206e654b49655b7d5c3b58ddd242b830
BLAKE2b-256 ce4031a0bf353efb1e9e5fce47f6744f77010dd7b80a84973084cb628df80b22

See more details on using hashes here.

Provenance

The following attestation bundles were made for diaphora_python-0.1.5.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.5-py3-none-any.whl.

File metadata

  • Download URL: diaphora_python-0.1.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 deb91f9d2620252d64d406fd8bc5842f9451f83aef099dae25a2a05b99218a36
MD5 1cf10492cc77a23300e7dc964ac570b5
BLAKE2b-256 05dfb8f7897c01cf3e564b07cea81efcfd5cd6d3e7a4a2e7e7700e2bdcde9553

See more details on using hashes here.

Provenance

The following attestation bundles were made for diaphora_python-0.1.5-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