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
Cardis the atomic unit of information.- Logical "updates" are done by creating a new
Card(for example,Card.update(...)returns a new object with a newcard_id). - This makes transformation flows traceable and auditable.
2. Linear Context Container
CardBoxis an ordered collection ofcard_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
CardStoreis the read/write entry point for cards and delegates persistence to storage adapters.CardBoxstores references only; actual card data is loaded from the storage layer.
4. Strategy-Based Extensibility
- Business logic is encapsulated in independent
Strategyunits. ContextEngine.transform(...)orchestrates strategy chains with low coupling between strategies.- Built-in examples:
ExtractCodeStrategy,PdfToTextStrategy,InlineTextFileContentStrategy.
5. Explicit Traceability
ContextEnginecan logCardandCardBoxtransformation history based onhistory_level.trace_idspans 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: Providestransform,to_api, andcall_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:
- Initialize
AsyncPostgresStorageAdapter(with optional auto bootstrap). - Create and persist
Cardinstances. - Save and load a
CardBox. - 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.pydepends 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2202391c12c48d89a827fc8fa0994d4ae7c05d4c4bca8487bd0fab906a53acfc
|
|
| MD5 |
73853eeb1d0aaa3abe95f58764826a16
|
|
| BLAKE2b-256 |
259a4e8df8dd268fd64084b829e7edd1898bd062cbb2da049529066105fc892b
|
Provenance
The following attestation bundles were made for cardbox-0.0.1.tar.gz:
Publisher:
publish.yml on Intelligent-Internet/CG-Cardbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardbox-0.0.1.tar.gz -
Subject digest:
2202391c12c48d89a827fc8fa0994d4ae7c05d4c4bca8487bd0fab906a53acfc - Sigstore transparency entry: 1396041641
- Sigstore integration time:
-
Permalink:
Intelligent-Internet/CG-Cardbox@1bd6d0d4db6d0b95e79d6262fa8df21389987b08 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Intelligent-Internet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1bd6d0d4db6d0b95e79d6262fa8df21389987b08 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f27a641d11115734701016d104e6f85763bc67cf5e0d2e8c3121132635f6257d
|
|
| MD5 |
7df87b823c0729a3086eb95d92fde2ed
|
|
| BLAKE2b-256 |
ed23b7ec451b36ea9f4bc4acf1f4e0d925bb92ebc74c0843a11c6f77d8c4bfc4
|
Provenance
The following attestation bundles were made for cardbox-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on Intelligent-Internet/CG-Cardbox
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cardbox-0.0.1-py3-none-any.whl -
Subject digest:
f27a641d11115734701016d104e6f85763bc67cf5e0d2e8c3121132635f6257d - Sigstore transparency entry: 1396041659
- Sigstore integration time:
-
Permalink:
Intelligent-Internet/CG-Cardbox@1bd6d0d4db6d0b95e79d6262fa8df21389987b08 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Intelligent-Internet
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1bd6d0d4db6d0b95e79d6262fa8df21389987b08 -
Trigger Event:
push
-
Statement type: