Skip to main content

 English  | 中文 

cardbox

cardbox is a data and context orchestration library centered around Card and CardBox.

Core Design Principles

1. Immutable Core Data

  • Card is the atomic unit of information.
  • Logical "updates" are done by creating a new Card (for example, Card.update(...) returns a new object with a new card_id).
  • This makes transformation flows traceable and auditable.

2. Linear Context Container

  • CardBox is an ordered collection of card_ids.
  • The main workflow processes context in linear order to keep complexity low.
  • Multi-turn context and strategy transformations are all built around CardBox.

3. Centralized State Management

  • CardStore is the read/write entry point for cards and delegates persistence to storage adapters.
  • CardBox stores references only; actual card data is loaded from the storage layer.

4. Strategy-Based Extensibility

  • Business logic is encapsulated in independent Strategy units.
  • ContextEngine.transform(...) orchestrates strategy chains with low coupling between strategies.
  • Built-in examples: ExtractCodeStrategy, PdfToTextStrategy, InlineTextFileContentStrategy.

5. Explicit Traceability

  • ContextEngine can log Card and CardBox transformation history based on history_level.
  • trace_id spans an entire processing flow for correlated auditing.

Core Components

  • Card: Supports text, JSON, tool calls, file references, and more.
  • CardBox: Ordered sequence of context references.
  • ContextEngine: Provides transform, to_api, and call_model.
  • AsyncPostgresStorageAdapter: Async PostgreSQL persistence.
  • LLMAdapter: Unified LLM access (LiteLLM / optional Interactions backend).

Installation

python -m venv .venv
source .venv/bin/activate
pip install -e .

From PyPI:

pip install cardbox

Optional extras:

pip install -e .[test]
pip install -e .[interactions]

If you want the packaged demo command through uv:

uv tool install cardbox
cardbox

PostgreSQL Configuration

Set one of the following DSN environment variables:

export POSTGRES_STORAGE_ADAPTER_DSN="postgresql://user:pass@localhost:5432/cardbox_db"
# or
export CARD_BOX_POSTGRES_DSN="postgresql://user:pass@localhost:5432/cardbox_db"

Run the Demo

main.py demonstrates a minimal end-to-end flow:

  1. Initialize AsyncPostgresStorageAdapter (with optional auto bootstrap).
  2. Create and persist Card instances.
  3. Save and load a CardBox.
  4. Print the loaded result.

Run:

python main.py

or, after installation:

cardbox

Run Tests

python -m unittest discover -s tests -p 'test_*.py' -v

Notes:

  • tests/test_llm_providers.py depends on external model environment variables and will be skipped when not configured.
  • Other tests prefer local stubs and avoid real external services.

Override Configuration

Use configure at startup to override default settings:

from cardbox.config import configure

configure({
    "POSTGRES_STORAGE_ADAPTER": {
        "dsn": "postgresql://user:pass@localhost:5432/cardbox_db",
        "auto_bootstrap": True,
    },
    "LLM_BACKEND": "litellm",
})

Metadata

Release files for cardbox 0.0.1

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

Source distribution (sdist)

Source distribution for cardbox 0.0.1
File Size Uploaded Provenance
cardbox-0.0.1.tar.gz 172.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cardbox 0.0.1
File Interpreter ABI Platform
cardbox-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 211.2 kB

Release files / cardbox-0.0.1.tar.gz

Download URL cardbox-0.0.1.tar.gz
Size 172.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2202391c12c48d89a827fc8fa0994d4ae7c05d4c4bca8487bd0fab906a53acfc
BLAKE2b-256 checksum
How to use checksums
259a4e8df8dd268fd64084b829e7edd1898bd062cbb2da049529066105fc892b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.

Transparency log

Release files / cardbox-0.0.1-py3-none-any.whl

Download URL cardbox-0.0.1-py3-none-any.whl
Size 38.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f27a641d11115734701016d104e6f85763bc67cf5e0d2e8c3121132635f6257d
BLAKE2b-256 checksum
How to use checksums
ed23b7ec451b36ea9f4bc4acf1f4e0d925bb92ebc74c0843a11c6f77d8c4bfc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.

Transparency log

Security for cardbox 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cardbox-0.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

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