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.13.49

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.13.49
File Size Uploaded
capdag_cartridge_sdk-1.13.49.tar.gz 17.7 kB Details

Built distribution (wheel)

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

Total release size: 32.0 kB

Release files / capdag_cartridge_sdk-1.13.49.tar.gz

Download URL capdag_cartridge_sdk-1.13.49.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ef6ba55d4795e1768beb7ae4a7c1d781d84901b23e8265cad94334d4e433bcd5
BLAKE2b-256 checksum
How to use checksums
3f5dd1d49097001a266e62af16af77b1e58132eb82841271ed556141ae49d907
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.13.49-py3-none-any.whl

Download URL capdag_cartridge_sdk-1.13.49-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5423889a543dd89d161847ed26182937b6cd075d550fdcb9401f63a30502928b
BLAKE2b-256 checksum
How to use checksums
70964ba045d7d2ffef65a3a789bd2febca39460235ed1133dba7a08495c0adb2
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

1.15.2

2 release files

This release

1.13.49 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