Skip to main content

SDK to build kin used in DigitalKin

Project description

DigitalKin Python SDK

CI PyPI Python Version License

The DigitalKin Python SDK for building and managing modules within the DigitalKin agentic mesh. Create custom Tools and Archetypes that communicate over gRPC, register with a service mesh, and scale independently.

Features

  • Async-native gRPC module system — every module is a gRPC server built on grpcio with full async support
  • Typed module contracts — Pydantic models for Input, Output, Setup, and Secret schemas with protocol-based trigger dispatch
  • Module-to-module communication — tools and archetypes discover each other via the registry and exchange requests over gRPC
  • Tool resolution — archetypes dynamically resolve and invoke tool modules at runtime
  • Admission queue & backpressure — built-in request admission with configurable concurrency limits
  • Healthcheck protocols — automatic ping, services, and status healthcheck triggers registered on every module
  • Profiling — optional [profiling] extra with asyncio-inspector, pyinstrument, viztracer, and yappi
  • Batched history writes — efficient storage writes for conversation history
  • TaskIQ integration — optional distributed task execution backed by RabbitMQ and Redis ([taskiq] extra)

Installation

# With uv (recommended)
uv add digitalkin

# With pip
pip install digitalkin

Optional extras:

# Distributed task execution (RabbitMQ + Redis)
uv add "digitalkin[taskiq]"

# Async profiling tools
uv add "digitalkin[profiling]"

Quick Start

1. Define your models

from pydantic import BaseModel
from digitalkin.models.module.base_types import DataModel, DataTrigger


class MessageInput(DataTrigger):
    protocol: str = "message"
    content: str


class InputModel(DataModel[MessageInput]):
    root: MessageInput


class MessageOutput(DataTrigger):
    protocol: str = "message"
    reply: str


class OutputModel(DataModel[MessageOutput]):
    root: MessageOutput

2. Create a module and trigger

from digitalkin import ArchetypeModule, ModuleContext, TriggerHandler
from digitalkin.models.module.setup_types import SetupModel


class MyArchetype(ArchetypeModule[InputModel, OutputModel, SetupModel, BaseModel]):
    async def initialize(self, context: ModuleContext, setup_data: SetupModel) -> None:
        pass

    async def cleanup(self, context: ModuleContext) -> None:
        pass


@MyArchetype.register
class MessageTrigger(TriggerHandler[InputModel, SetupModel, OutputModel]):
    protocol = "message"
    input_format = InputModel
    output_format = OutputModel

    def __init__(self, context: ModuleContext) -> None:
        super().__init__(context)

    async def handle(
        self,
        input_data: InputModel,
        setup_data: SetupModel,
        context: ModuleContext,
    ) -> None:
        output = OutputModel(root=MessageOutput(reply=f"Echo: {input_data.root.content}"))
        await self.send_message(context, output)

3. Run the server

import asyncio
from digitalkin.grpc_servers.module_server import ModuleServer

async def main() -> None:
    server = ModuleServer(MyArchetype)
    await server.start_async()
    await server.await_termination()

asyncio.run(main())

TaskIQ with RabbitMQ

TaskIQ integration allows the module to scale for heavy CPU tasks by distributing requests to stateless worker instances.

  • Decoupled Scalability: RabbitMQ brokers messages, letting producers and consumers scale independently.
  • Reliability: Durable queues, acknowledgements, and dead-lettering ensure tasks aren't lost.
  • Concurrency Control: TaskIQ's worker pool manages parallel execution without custom schedulers.
  • Flexibility: Built-in retries, exponential backoff, and Redis result-backend for resilient workflows.

To enable RabbitMQ streaming:

sudo rabbitmq-plugins enable rabbitmq_stream
task start-taskiq

Development

Prerequisites

  • Python 3.10+
  • uv — modern Python package management
  • Task — task runner

Setup

git clone --recurse-submodules https://github.com/DigitalKin-ai/digitalkin.git
cd digitalkin

task setup-dev
source .venv/bin/activate

Common Tasks

task linter               # Format + lint (ruff) + type check (mypy)
task check                # Linter + mypy + tests
task run-tests            # Run pytest via Docker
task build-package        # Build distribution
task bump-version -- patch|minor|major

task docs-serve           # Serve docs locally (mkdocs)
task docs-build           # Build docs

task generate-certificates  # Generate mTLS certs for gRPC
task start-taskiq           # Start TaskIQ worker

task clean                # Remove build artifacts + __pycache__
task clean-all            # Above + remove .venv

Publishing Process

  1. Update code and commit changes (following conventional branch/commit standard).
  2. Use task bump-version -- major|minor|patch to commit the new version.
  3. Use GitHub "Create Release" workflow to publish the new version.
  4. Workflow automatically publishes to Test PyPI and PyPI.

License

This project is licensed under the terms specified in the LICENSE file.


For more information, visit our Documentation or report issues on our Issues page.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

digitalkin-0.4.3.dev1.tar.gz (206.2 kB view details)

Uploaded Source

Built Distribution

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

digitalkin-0.4.3.dev1-py3-none-any.whl (276.6 kB view details)

Uploaded Python 3

File details

Details for the file digitalkin-0.4.3.dev1.tar.gz.

File metadata

  • Download URL: digitalkin-0.4.3.dev1.tar.gz
  • Upload date:
  • Size: 206.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for digitalkin-0.4.3.dev1.tar.gz
Algorithm Hash digest
SHA256 ad6324cdcc1a2a365539bcf1f188da3db889b0a49ed09d4f62eec874790ea3a4
MD5 f8f80f91a470700c29cdcfe12105d13a
BLAKE2b-256 7cf8c7b4e48421c92b452a117407e2105bad3ed48edc2d6cd45d7cbaea62f0db

See more details on using hashes here.

Provenance

The following attestation bundles were made for digitalkin-0.4.3.dev1.tar.gz:

Publisher: release.yml on DigitalKin-ai/digitalkin

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

File details

Details for the file digitalkin-0.4.3.dev1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for digitalkin-0.4.3.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 288d1bfd5fc2987cb429c457966423a995aa09bdb0f6f02e224956537ef31f35
MD5 c0f4c168e3222e8b8ef7058abec73bc7
BLAKE2b-256 ef77ec754bcce05782153138059f7071a28d3361adc18eacd4db59bdd38b4a50

See more details on using hashes here.

Provenance

The following attestation bundles were made for digitalkin-0.4.3.dev1-py3-none-any.whl:

Publisher: release.yml on DigitalKin-ai/digitalkin

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