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",
})
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cardbox-0.0.1.tar.gz | 172.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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 logRelease 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 logSecurity 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.
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 logA 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.