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.51.71
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| capdag_cartridge_sdk-1.51.71.tar.gz | 17.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| capdag_cartridge_sdk-1.51.71-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.0 kB
Release files / capdag_cartridge_sdk-1.51.71.tar.gz
| Download URL | capdag_cartridge_sdk-1.51.71.tar.gz |
|---|---|
| Size | 17.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e3436db35d4cc687010b9eb96c059a2f0b20a7dcaf061dbae3a78e0e738b9a6
|
|
BLAKE2b-256 checksum How to use checksums |
ea7eb6426f4173a29329ff07a80b9f5305615ad34b27e432ea5079c1aabeddbf
|
| 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.51.71-py3-none-any.whl
| Download URL | capdag_cartridge_sdk-1.51.71-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa8c4d38b51cf7e5596840d399016286bbda26f297c94dad1e36f5c159d45b34
|
|
BLAKE2b-256 checksum How to use checksums |
92682c4221b02da746dbfb0346dae9b23981435c25da78842c97ca5247e0ffa0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|