Skip to main content

dhara-extension-py

Python SDK for building Dhara extensions.

Installation

pip install dhara-extension

Or install from source:

cd packages/dhara-extension-py
pip install -e .

Quick Start

Create a file hello-ext/main.py:

#!/usr/bin/env python3
"""A simple Dhara extension using the Python SDK."""

from dhara_extension import Extension

ext = Extension(
    name="hello-ext",
    version="1.0.0",
    description="A friendly hello extension",
)

@ext.tool(
    name="hello",
    description="Greet someone by name",
    parameters={
        "type": "object",
        "properties": {
            "name": {
                "type": "string",
                "description": "Name to greet",
            },
        },
        "required": ["name"],
    },
)
def hello(input_data):
    name = input_data.get("name", "World")
    greeting = f"Hello, {name}! Welcome to Dhara."
    return {
        "content": [
            {"type": "text", "text": greeting},
        ],
    }

@ext.tool(
    name="count",
    description="Count items in a list",
)
def count(input_data):
    items = input_data.get("items", [])
    return {
        "content": [
            {"type": "text", "text": f"Counted {len(items)} items."},
        ],
    }

if __name__ == "__main__":
    ext.run()

And a manifest.json:

{
    "name": "hello-ext",
    "version": "1.0.0",
    "runtime": {
        "type": "subprocess",
        "command": "python3 main.py",
        "protocol": "json-rpc"
    },
    "provides": {
        "tools": ["hello", "count"]
    },
    "capabilities": []
}

API Reference

Extension(name, version, description="", debug=False)

Main extension class.

  • tool(name, description, parameters, capabilities) — Decorator to register a tool handler
  • run() — Start the JSON-RPC stdin/stdout loop

create_extension(name, version, description="")

Convenience function to create an Extension instance.

Protocol

Extensions communicate with Dhara via JSON-RPC 2.0 over stdin/stdout:

→ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}
← {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"0.1.0","name":"hello-ext","tools":[...]}}

→ {"jsonrpc":"2.0","id":2,"method":"tools/execute",
     "params":{"toolName":"hello","input":{"name":"World"}}}
← {"jsonrpc":"2.0","id":2,"result":{"content":[{"type":"text","text":"Hello, World!"}]}}

See the Dhara Extension Protocol for details.

Metadata

Release files for dhara-extension 0.7.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dhara-extension 0.7.4
File Size Uploaded Provenance Actions
dhara_extension-0.7.4.tar.gz 6.3 kB Without provenance Details for dhara_extension-0.7.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dhara-extension 0.7.4
File Interpreter ABI Platform Actions
dhara_extension-0.7.4-py3-none-any.whl Python 3 none any Details for dhara_extension-0.7.4-py3-none-any.whl

Total release size: 12.5 kB

Release files / dhara_extension-0.7.4.tar.gz

Download URL dhara_extension-0.7.4.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
64499bb4c8414166b879f9596b0c898286747fd30429b136ed7286e93e2f32ec
BLAKE2b-256 checksum
How to use checksums
3f6bccc41e104c998ba49615a2ea2d9e2090774f903c0119734cd79c0f7d2631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / dhara_extension-0.7.4-py3-none-any.whl

Download URL dhara_extension-0.7.4-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56ea4cc4f91727cd7d3d109277f06ec01d95ec85a812c699a61b84d3306d3b21
BLAKE2b-256 checksum
How to use checksums
69a49792490086ea59ddc6b4c4f549ab0b8cd508a2cc4410466c11e0a1e7e241
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for dhara-extension 0.7.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page