Skip to main content

MachineFabric cartridge SDK for Python

This public Python package mirrors the Rust machfab-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 machfab-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
machfab_cartridge_sdk.llm LLM request, stream, vocabulary and model-information records, media URNs, cap URNs, and backend_for_model_spec classification.
machfab_cartridge_sdk.prompt Prompt-strategy classification and the shared default system prompt.
machfab_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 machfab_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 machfab_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 MachineFabric-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 machfab-cartridge-sdk 1.4.31

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

Source distribution (sdist)

Source distribution for machfab-cartridge-sdk 1.4.31
File Size Uploaded
machfab_cartridge_sdk-1.4.31.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for machfab-cartridge-sdk 1.4.31
File Interpreter ABI Platform
machfab_cartridge_sdk-1.4.31-py3-none-any.whl Python 3 none any Details

Total release size: 32.0 kB

Release files / machfab_cartridge_sdk-1.4.31.tar.gz

Download URL machfab_cartridge_sdk-1.4.31.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
86d5d66ba22a95c2d6b9f4b7579c15dd1ea029c5958233fe1c6852493ba38ae9
BLAKE2b-256 checksum
How to use checksums
b7cbf68d7d674384d46bcb112f229e00cbe05627455cb80184389a52d4099cb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / machfab_cartridge_sdk-1.4.31-py3-none-any.whl

Download URL machfab_cartridge_sdk-1.4.31-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93eff104e878d91089b88170524088ed4daf17e9647f208bcedfa978deadee85
BLAKE2b-256 checksum
How to use checksums
22c09c8abc637ca7f55d5588916166851a7b95ea5efe46ee74101bc5df1d99fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release history Release notifications | RSS feed

This release

1.4.31 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