Skip to main content

Card-box based context management core library.

Project description

 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",
})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cardbox-0.0.1.tar.gz (172.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cardbox-0.0.1-py3-none-any.whl (38.4 kB view details)

Uploaded Python 3

File details

Details for the file cardbox-0.0.1.tar.gz.

File metadata

  • Download URL: cardbox-0.0.1.tar.gz
  • Upload date:
  • Size: 172.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cardbox-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2202391c12c48d89a827fc8fa0994d4ae7c05d4c4bca8487bd0fab906a53acfc
MD5 73853eeb1d0aaa3abe95f58764826a16
BLAKE2b-256 259a4e8df8dd268fd64084b829e7edd1898bd062cbb2da049529066105fc892b

See more details on using hashes here.

Provenance

The following attestation bundles were made for cardbox-0.0.1.tar.gz:

Publisher: publish.yml on Intelligent-Internet/CG-Cardbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cardbox-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: cardbox-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cardbox-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f27a641d11115734701016d104e6f85763bc67cf5e0d2e8c3121132635f6257d
MD5 7df87b823c0729a3086eb95d92fde2ed
BLAKE2b-256 ed23b7ec451b36ea9f4bc4acf1f4e0d925bb92ebc74c0843a11c6f77d8c4bfc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cardbox-0.0.1-py3-none-any.whl:

Publisher: publish.yml on Intelligent-Internet/CG-Cardbox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page