# OFAC API integration: practice result handling in Python

Run seven invented response scenarios locally and see how a screening workflow
handles a no-match result, a potential match, and failures. This example needs
Python 3.9 or later, no installed packages, no API key, and no network connection.

**Every record, result, score, timestamp, and source version here is an illustrative
fixture.** The example does not fetch OFAC data, run matching, call SanctionsKit,
or establish screening accuracy. `sandbox-synthetic` identifies synthetic
coverage; it does not identify an OFAC list.

## Run

Save [demo.py](./demo.py), inspect it, and run:

```sh
python3 -B demo.py
python3 -B demo.py --scenario potential-match
```

One redacted JSON summary is printed for each scenario. `fixture_only` is always
`true`. The command exits successfully when it has demonstrated the selected
scenario, including an expected failure; exit status is not a screening result.

| Scenario              | Workflow state    | What the application should do next                                    |
| --------------------- | ----------------- | ---------------------------------------------------------------------- |
| `no-match`            | `no_match`        | Apply any remaining policy, ownership, and due-diligence requirements. |
| `potential-match`     | `review_required` | Route candidates and protected evidence to an authorized reviewer.     |
| `inconsistent-result` | `incomplete`      | Investigate the conflicting status and candidate list.                 |
| `stale-coverage`      | `incomplete`      | Resolve the coverage problem before using a result.                    |
| `malformed-json`      | `incomplete`      | Treat the response as unusable.                                        |
| `http-error`          | `incomplete`      | Resolve the API failure; no completed result was received.             |
| `transport-error`     | `incomplete`      | Reconcile an uncertain request before deciding how to retry.           |

Every branch leaves `business_disposition` as `pending`. A completed screening is
not a business approval or legal clearance. A potential match requires review even
if its numeric score is low; a score is not a probability of identity or wrongdoing.

## Read the workflow

`REQUEST` shows an invented request body. `fixtures()` supplies HTTP-style inputs
without making requests. `route_response()` consumes the documented `201` response
envelope, `{"data": ...}`, checks the fields and consistency needed by this example,
then returns only fixed labels and counts. It rejects a mismatched environment or
package, missing or unexpected source coverage, stale coverage, inconsistent
status/candidate counts, and malformed inputs.

These checks are intentionally scoped to the example's one synthetic source and
person subject. They are not a full API schema validator, a replacement SDK,
production coverage discovery, or a complete compliance workflow. New production
results can carry source notices, matching details, and an approved policy
snapshot; preserve that context in authorized evidence storage rather than copying
this minimal fixture as a complete production record.

## Connect the idea to an actual integration

Use the [OFAC API guide](https://www.sanctionskit.com/guides/ofac-api) and
[API reference](https://www.sanctionskit.com/docs/api-reference) for the full
request, authentication, error, evidence, and policy contracts. The published
[OpenAPI document](https://www.sanctionskit.com/openapi.json) is the schema reference.

- Optional sandbox requests use `package: "sandbox@1"` and made-up records.
  Sign up to get 250 free live screenings for the life of your workspace, shared by the API
  and dashboard. These checks do not reset each month. No credit card is needed.
  Live requests use a production key and available qualified coverage. Choose a
  paid plan when you need more checks. Never change an environment label to turn
  a fixture into production evidence.
- Choose exactly one of `package` or `sources`. For production, discover available
  source IDs through `GET /sources`; source availability alone is not proof that an
  arbitrary requested package is available. If an approved organization policy is
  required, retrieve `GET /policies` and supply its exact `id` and `version` with
  the required coverage. Policy-based production screening uses explicit sources.
- OFAC publishes sanctions data and search resources. This example models a
  SanctionsKit response; it does not demonstrate a Treasury customer-screening API
  or an official OFAC endorsement.
- Use an API client for actual network calls. Keep the original request body and
  idempotency key stable when retrying an operation with a documented idempotency
  contract. A timeout can happen after a request commits. Never substitute an
  empty candidate list when a request fails.
- Retain result identifiers, coverage versions, interpretation limits, and review
  decisions in access-controlled records according to your retention policy.
  Keep API keys, subject inputs, raw errors, and full evidence out of ordinary logs.

## Verify the example

Save [test_demo.py](./test_demo.py) beside `demo.py`, then run:

```sh
python3 -B -m unittest discover -s . -p 'test_demo.py' -v
```

The tests exercise response routing, failure handling, candidate/coverage
consistency, and output redaction. Passing these local fixture tests does not
demonstrate a successful API call, actual source freshness, matching accuracy,
hosted availability, production qualification, or completed analyst review.
