Metadata-Version: 2.5
Name: statement-fetch
Version: 0.5.0
Summary: Zero-LLM-in-Bank async financial statement fetcher, validator, and pluggable sink runner.
Project-URL: Homepage, https://github.com/benjamin-di/statement-fetch-oss
Project-URL: Repository, https://github.com/benjamin-di/statement-fetch-oss
Author: benjamin-di
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Provides-Extra: playwright
Requires-Dist: playwright<2,>=1.52; extra == 'playwright'
Description-Content-Type: text/markdown

# statement-fetch

Zero-LLM-in-Bank async financial statement fetcher, structural validator, and pluggable sink runner.

## Security Model ("Zero-LLM-in-Bank")

1. **Human sign-in:** A real Chromium browser opens the institution's login URL. The human completes authentication and 2FA; no credentials or LLM tokens touch the bank session.
2. **Host confinement:** Top-level navigations, HTTP 3xx redirects (single/multi-hop and POST), `target="_blank"` popups, and in-page `fetch_bytes()` calls are confined to the provider's declared `allowed_hosts` via Chromium CDP `Fetch.enable` and context routing.
3. **Deterministic fetch & atomic staging:** After `is_logged_in()` succeeds, deterministic provider code downloads statements into a per-run `0o700` staging directory, validates every artifact using its declared validator (defaulting to non-empty; built-in validators cover PDF, CSV, JSON, and bounded ZIP), writes `0o600` artifacts with SHA-256 digests, and produces a portable `manifest.json`.
4. **Guaranteed logoff & pluggable sinks:** `logoff()` and browser teardown run in `finally:` even on error or Ctrl-C. Sinks (`statement_fetch.sinks`) verify every manifest entry and SHA-256 before delivering.

## Installation

Requires Python 3.11+:

```bash
pip install "statement-fetch[playwright]"
playwright install chromium
```

## Quickstart (Demo Portal, From a Clone)

Install Chromium into the project environment:

```bash
uv run --extra playwright playwright install chromium
```

In one terminal, start the bundled zero-dependency loopback demo bank:

```bash
uv run python -m statement_fetch.demo --port 8765
```

In another terminal, fetch statements and export them to a local directory with an immutable receipt manifest:

```bash
uv run --extra playwright statement-fetch fetch example-bank \
  --opt base_url=http://127.0.0.1:8765 \
  --upload --sink dir --sink-dir ./exported
```

Verify a staged or exported manifest offline:

```bash
uv run statement-fetch upload ./exported/manifest-*.json --local-only --json
```

## Plugin API (`API_VERSION = 1`)

Third-party providers and sinks import from `statement_fetch.api` (or top-level `statement_fetch`) and register via Python entry points:

```toml
[project.entry-points."statement_fetch.providers"]
my-bank = "my_pkg.provider:MyBankProvider"

[project.entry-points."statement_fetch.sinks"]
my-sink = "my_pkg.sink:MySink"
```

- Reference provider: `src/statement_fetch/providers/example_bank.py`
- Reference sink: `src/statement_fetch/sinks/directory.py`
- Versioning: the entry-point group names (`statement_fetch.providers`, `statement_fetch.sinks`) define the `API_VERSION = 1` compatibility boundary.

## CLI Exit Codes & Manifest Schema

- **Exit codes:** `0` (`EXIT_OK`, ok/empty), `1` (`EXIT_ERROR`), `2` (`EXIT_USAGE`), `3` (`EXIT_LOGIN_TIMEOUT`), `4` (`EXIT_PARTIAL`), `130` (interrupted / Ctrl-C).
- **`manifest.json` (`schema_version = 1`):** `schema_version`, `api_version`, `tool_version`, `created_at`, `provider`, `period_start`, `period_end`, `artifacts[]` (`artifact_id`, `name`, `path` relative to manifest dir, `sha256`, `bytes`, `provider`, `kind`, `period`, `valid`, optional `currency`/`error`/`observed_start`/`observed_end`/`meta`), `skipped[]`, `errors[]`, `timings_s`.

## Development Checks

```bash
make check
```
