Skip to main content

CapDAG Cartridge SDK for Python

This public Python package mirrors the Rust capdag-cartridge-sdk. It is for Python cartridge authors who need the canonical request, stream, vocabulary and model-information records, the media and cap URNs that carry them, the prompt-strategy decision, and the shared page-selection grammar.

Install

pip install capdag-cartridge-sdk

The cartridge runtime itself — the bifaci host loop, cap registration, the manifest, peer calls — is capdag's. A cartridge installs both and imports each for what it owns; this package declares no dependency on capdag, so a release of one never waits on the other.

Layout

Module Contract
capdag_cartridge_sdk.llm LLM request, stream, vocabulary and model-information records, media URNs, cap URNs, and backend_for_model_spec classification.
capdag_cartridge_sdk.prompt Prompt-strategy classification and the shared default system prompt.
capdag_cartridge_sdk.pages One-based page/index selection with ordered, deduplicated, clamped ranges.

The reference also ships net_retry (a retry policy written directly on reqwest's types) and structured_queries (a Tera-rendered query registry). Neither is in this mirror, and neither is stubbed: a function that exists and does nothing is worse than one that is absent, because it is discovered at runtime rather than at import.

Usage

from capdag_cartridge_sdk.llm import (
    BACKEND_GGUF,
    CAP_LLM_INFERENCE_GGUF,
    LlmGenerationRequest,
    backend_for_model_spec,
)

request = LlmGenerationRequest.with_defaults(
    "Summarize this document",
    "hf:Qwen/Qwen2.5-0.5B-Instruct",
)
print(request.to_json())

if backend_for_model_spec(request.model_spec) == BACKEND_GGUF:
    ...  # dispatch to CAP_LLM_INFERENCE_GGUF

Preparing a prompt for whichever model was downloaded:

from capdag_cartridge_sdk.prompt import (
    DEFAULT_SYSTEM_PROMPT,
    ChatTemplated,
    RefinedDims,
    classify_prompt,
)

strategy = classify_prompt(
    RefinedDims(chat_template=dims["chat_template"]),
    user_text,
    DEFAULT_SYSTEM_PROMPT,
)
if isinstance(strategy, ChatTemplated):
    ...  # render through the model's own chat template, specials parsed
else:
    ...  # tokenize strategy.text verbatim

Verify changes

PYTHONPATH=src python -m pytest tests/ -q

The Rust SDK is authoritative for CapDAG-specific wire types, and the numbered tests here are the reference's numbers: test0001–test0010 are its llm tests, test0011–test0016 its prompt tests, and test0060–test0062 its pages tests. A change to a shared wire type or a prompt decision is mirrored here — implementation and same-numbered tests — in the same change. Language-neutral runtime behavior belongs to the CapDAG specification.

Metadata

Release files for capdag-cartridge-sdk 1.15.2

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

Source distribution (sdist)

Source distribution for capdag-cartridge-sdk 1.15.2
File Size Uploaded
capdag_cartridge_sdk-1.15.2.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for capdag-cartridge-sdk 1.15.2
File Interpreter ABI Platform
capdag_cartridge_sdk-1.15.2-py3-none-any.whl Python 3 none any Details

Total release size: 32.0 kB

Release files / capdag_cartridge_sdk-1.15.2.tar.gz

Download URL capdag_cartridge_sdk-1.15.2.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6208ce983a3f76de86dbbf785d88b11eec8d5efc16dfaadb11d763205705509a
BLAKE2b-256 checksum
How to use checksums
1f85fccc7f74cbb1d03eb750e8a6c032252d0e6aa6dd548b1537a733e42d3663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / capdag_cartridge_sdk-1.15.2-py3-none-any.whl

Download URL capdag_cartridge_sdk-1.15.2-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d290e03eaced6b309e88a9444e7ba531ce6c7365bb11705ef64f7b7c0fcead5
BLAKE2b-256 checksum
How to use checksums
f242c85ce0ed83f2de805af4a0e71cec251275ef46af9293d0614bc6d4b562bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release history Release notifications | RSS feed

This release

1.15.2 This release

2 release files

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