Metadata-Version: 2.4
Name: framelens
Version: 0.4.1
Summary: FrameLensAI Python SDK - eval and regression testing for video AI
Author: FrameLensAI
License-Expression: Apache-2.0
Keywords: video,evaluation,eval,regression-testing,vlm,machine-learning,llm,ci
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Multimedia :: Video
Classifier: Framework :: Pytest
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Dynamic: license-file

# framelens

**Python client for FrameLensAI —
evaluation and regression testing for video AI.**

FrameLensAI turns *"did the new model get worse?"* from a vibe into a gated,
statistical answer: versioned video test suites → provider-neutral eval runs →
video-native metrics with confidence intervals → CI gates that block confident
regressions.

This package is the **client**. It talks to a FrameLens server (self-hosted via
`docker compose`, or run locally with `make dev`); it does not run evals by
itself.

```bash
pip install framelens
```

Requires Python 3.10+. The only dependency is `httpx`.

## Quickstart

```python
from framelens import FrameLens

fl = FrameLens(api_key="dev-key", base_url="http://localhost:8000")

sha     = fl.upload_video("clip.mp4")            # content-addressed; re-upload is a no-op
project = fl.create_project("perimeter-security")
dataset = fl.create_dataset(project["id"], "intrusion-events",
                            task_type="event_detection")
fl.add_case(dataset["id"], video_sha=sha,
            ground_truth={"events": [{"start_ms": 4200, "end_ms": 6100}]})
fl.freeze(dataset["id"])                         # immutable version snapshot

model = fl.create_model_config(project["id"], "gpt-4o", adapter="openai_compat",
                               params={"model": "gpt-4o"})   # api_key is encrypted server-side

run = fl.run(project["id"], dataset_id=dataset["id"],
             model_config_id=model["id"])
run = fl.wait(run["id"])                         # or fl.watch(...) for live SSE progress
print(run["summary"]["overall"]["event_f1"])
```

Runs are **idempotent**: the same `(dataset version, model config, prompt,
sampling)` tuple produces the same fingerprint, and the server returns the
existing run instead of paying for it twice. `run()` tells you which happened
via `outcome`: `created`, `cached`, `joined` or `resumed`.

## Gating a pull request

A gate fails only when a **paired bootstrap** says the regression is real —
never on a single point estimate.

```python
verdict = fl.gate(run["id"], baseline="main", gates=[
    {"metric": "event_f1",  "min_delta": -0.01},
    {"metric": "fa_per_min", "max_delta": 0.05, "slice": "tags.night"},
])

from framelens import raise_for_gates
raise_for_gates(verdict)      # FrameLensGateFailed, with a readable table
```

## Inside your own test suite

Installing the SDK auto-registers a pytest plugin (via the `pytest11` entry
point) — no `conftest.py` wiring:

```python
def test_no_regression(framelens_eval):
    result = framelens_eval(
        project_id, dataset_id=dataset_id, model_config_id=model_config_id,
        gates=[{"metric": "event_f1", "min_delta": -0.01}])
    result.assert_gates()
    assert result.metric("event_f1") > 0.8
```

Point it at a server with `--framelens-url` / `--framelens-key` (or
`FRAMELENS_API_URL` / `FRAMELENS_API_KEY`), and use `--framelens-subset smoke`
so a PR gates a smoke subset while the nightly gates the full suite.

## Async

`AsyncFrameLens` mirrors the sync client method for method:

```python
from framelens import AsyncFrameLens

async with AsyncFrameLens(api_key=..., base_url=...) as fl:
    run = await fl.run(project_id, dataset_id=..., model_config_id=...)
    run = await fl.wait(run["id"])
```

## Failures are typed, and carry the request id

Every error inherits from `FrameLensError` and carries the server's
`request_id`, so a failure in your CI log is findable in the server's:

`FrameLensAuthError` · `FrameLensPermissionError` · `FrameLensNotFoundError` ·
`FrameLensValidationError` · `FrameLensRateLimited` · `FrameLensServerError` ·
`FrameLensConnectionError` · `FrameLensTimeoutError` · `FrameLensVersionError` ·
`FrameLensRunFailed` · `FrameLensGateFailed`

Transient failures **retry** with jittered backoff honouring `Retry-After`: a
429 for every method (refused ⇒ not executed), a 5xx or transport error only
where repeating is safe — GET/DELETE plus the POSTs the API makes idempotent.

```python
fl = FrameLens(api_key=..., base_url=..., timeout=30.0,
               verify="/etc/ssl/corp-ca.pem")   # also: transport=, client=
```

## Large collections

List routes are cursor-paginated and capped; the SDK follows the cursor for
you.

```python
for prediction in fl.iter_predictions(run_id):   # streams, follows next_cursor
    ...
cases = fl.list_cases(dataset_id)                # same, materialised
```

## Versioning

Semver, pre-1.0: a minor bump may change behaviour, a patch may not.
`framelens.API_VERSION` is the API contract this client was written against and
is sent on every request, so an unsupported server answers at the first call
rather than deep inside a job.

## Licence

Apache-2.0. The full text ships inside the package (`LICENSE`).
