Metadata-Version: 2.5
Name: local-decision-store
Version: 0.1.7
Summary: Run typed decision models (Decisions API / System One compatible) locally on CPU.
Project-URL: Homepage, https://github.com/indxdev/local-decision-store
Project-URL: Source, https://github.com/indxdev/local-decision-store
Project-URL: Issues, https://github.com/indxdev/local-decision-store/issues
Project-URL: Documentation, https://github.com/indxdev/local-decision-store/tree/main/docs
Project-URL: Changelog, https://github.com/indxdev/local-decision-store/blob/main/CHANGELOG.md
Author: The Local Decision Store Authors
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: classification,cpu,decisions-api,embeddings,onnx,scikit-learn,tf-idf
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Requires-Dist: typing-extensions>=4.7; python_version < '3.11'
Provides-Extra: all
Requires-Dist: boto3>=1.35; extra == 'all'
Requires-Dist: cryptography>=44; extra == 'all'
Requires-Dist: lightgbm>=4.3; extra == 'all'
Requires-Dist: onnxruntime>=1.18; extra == 'all'
Requires-Dist: openai>=1.40; extra == 'all'
Requires-Dist: pillow>=10; extra == 'all'
Requires-Dist: pyarrow>=14; extra == 'all'
Requires-Dist: pyyaml>=6; extra == 'all'
Requires-Dist: scikit-learn>=1.4; extra == 'all'
Requires-Dist: sigstore>=4; extra == 'all'
Requires-Dist: starlette>=0.37; extra == 'all'
Requires-Dist: tokenizers>=0.19; extra == 'all'
Requires-Dist: uvicorn>=0.29; extra == 'all'
Requires-Dist: wasmtime>=25; extra == 'all'
Provides-Extra: bedrock
Requires-Dist: boto3>=1.35; extra == 'bedrock'
Provides-Extra: dev
Requires-Dist: cryptography>=44; extra == 'dev'
Requires-Dist: httpx2>=2; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: onnx>=1.16; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: pyyaml>=6; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Provides-Extra: embed
Requires-Dist: onnxruntime>=1.18; extra == 'embed'
Requires-Dist: tokenizers>=0.19; extra == 'embed'
Provides-Extra: generate
Requires-Dist: openai>=1.40; extra == 'generate'
Requires-Dist: pyyaml>=6; extra == 'generate'
Provides-Extra: image
Requires-Dist: pillow>=10; extra == 'image'
Provides-Extra: parquet
Requires-Dist: pyarrow>=14; extra == 'parquet'
Provides-Extra: server
Requires-Dist: starlette>=0.37; extra == 'server'
Requires-Dist: uvicorn>=0.29; extra == 'server'
Provides-Extra: sign
Requires-Dist: cryptography>=44; extra == 'sign'
Requires-Dist: sigstore>=4; extra == 'sign'
Provides-Extra: train
Requires-Dist: lightgbm>=4.3; extra == 'train'
Requires-Dist: scikit-learn>=1.4; extra == 'train'
Provides-Extra: wasm
Requires-Dist: wasmtime>=25; extra == 'wasm'
Provides-Extra: yaml
Requires-Dist: pyyaml>=6; extra == 'yaml'
Description-Content-Type: text/markdown

# local-decision-store (Python)

> **Status: alpha preview (pre-1.0).** Inference (lite and embed tiers), the server, training of lite packs,
> evaluation, data generation and the `lds` CLI work and are tested; APIs may still change before 1.0. The
> package is not on PyPI yet (install from a checkout: `pip install ./python`), and catalog packs are not
> published yet. See [`design/roadmap.md`](../design/roadmap.md).

This package provides the Python SDK, the `lds` CLI and the reference server for
**Local Decision Store**. It runs typed decision models locally on CPU, and its request and response
shapes are compatible with the OpenAI/Cloudflare **Decisions API** (`/v1/decisions`) and
TypeSafe **System One** (`/v1/systemone`).

```bash
pip install local-decision-store            # core (numpy only): lite tier inference
pip install "local-decision-store[embed]"   # + ONNX embedders (embed tier)
pip install "local-decision-store[yaml]"    # + PyYAML: lds.yaml and YAML question specs
pip install "local-decision-store[train]"   # + scikit-learn / LightGBM (gbdt heads)
pip install "local-decision-store[server]"  # + HTTP server (`lds serve`)
pip install "local-decision-store[wasm]"    # + custom WebAssembly featurizer ops (wasmtime)
pip install "local-decision-store[all]"
```

With a pack installed (for example the dev pack built by `lds init quickstart && cd quickstart && lds train &&
lds pack build runs/quickstart && lds pull packs/quickstart-lite-0.1.0.ldspack`):

<!-- doc-test -->
```python
import lds

client = lds.Client()  # in-process, packs from $LDS_HOME (~/.lds)
r = client.decisions.create(
    model="lds/lite",
    input="The checkout page is down, please fix this immediately",
    questions=[{"type": "predicate", "name": "quickstart.is_urgent", "instructions": "Urgent?"}],
)
print(r.answers[0].probability)
```

Training follows the scikit-learn style:

```python
from lds import Choice, DecisionClassifier

q = Choice("support.department", ["billing", "shipping", "technical", "other"], "Which team?")
clf = DecisionClassifier(q, tier="lite", head="linear").fit(texts, labels)
clf.save_pack("packs/support-department", version="0.1.0")
```

## Featurizers

Every kind of feature (TF-IDF, rule detectors, image statistics, embeddings, custom ops) goes through
one interface: a typed JSON graph that Python and TypeScript both run
([spec/featurizer.md §10](../spec/featurizer.md)). Build graphs with `lds.fx`. They are type-checked
when loaded, and `lds featurizer lint` runs the same check from the command line.

```python
from lds import Featurizer, fx

text = fx.normalize(fx.TEXT)
words = fx.hash(fx.word_ngrams(fx.word_tokens(text), n_min=1, n_max=2), bits=18)
f = Featurizer(words)  # scikit-learn transformer: fit / transform / fit_transform
f.transform(["Call me at 090-1234-5678"])
f.to_json()  # the same graph loads in TypeScript: Featurizer.fromJSON(...)

lite = Featurizer.from_preset("lite")  # presets: lite, lite-image, embed, embed-hybrid, embed-image
```

Custom logic is shipped as a sandboxed WebAssembly module, so one binary runs in both runtimes
([spec/wasm-ops.md](../spec/wasm-ops.md)). This needs the `wasm` extra:

```python
f = Featurizer(fx.wasm("ops/acme.jp_address.wasm", text), modules={"ops/acme.jp_address.wasm": wasm_bytes})
```

`lds op inspect module.wasm` validates a module and prints its op info.

## Development

```bash
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev,wasm]"
pytest && ruff check . && mypy
```

The normative behavior is defined in [`spec/`](../spec). This package must pass the shared
conformance fixtures in `spec/conformance/`.
