Metadata-Version: 2.4
Name: qaechi-contracts
Version: 1.0.1
Summary: Message and API contracts shared by Qaechi modules: Python models and JSON Schemas.
Author: Taeyong Kang
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/qaechi/qaechi-contracts
Project-URL: Documentation, https://qaechi.github.io/modules/
Project-URL: Issues, https://github.com/qaechi/qaechi-contracts/issues
Project-URL: Changelog, https://github.com/qaechi/qaechi-contracts/blob/main/CHANGELOG.md
Keywords: qaechi,contracts,json-schema,kafka,events
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
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
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic<3,>=2.6
Provides-Extra: dev
Requires-Dist: pytest<10,>=8; extra == "dev"
Requires-Dist: jsonschema<5,>=4.26; extra == "dev"
Requires-Dist: ruff==0.16.*; extra == "dev"
Dynamic: license-file

# qaechi-contracts

The messages and API shapes every [qaechi](https://qaechi.github.io/) module speaks: Python models
and JSON Schemas. Build a producer, a consumer or a client in any language against these and it
works with any qaechi release of the same major version.

[한국어](README.ko.md) | [How the modules fit together](https://qaechi.github.io/modules/)

```bash
pip install qaechi-contracts
```

```python
from qaechi.contracts import JobMessage, JobRequest, ResultEvent, Topics

msg = JobMessage(job_id="4f6c2a0e-...", request=JobRequest(
    document_id="inv-2026-0042", source="invoices/0042.pdf", doc_type="invoice"))
producer.produce(Topics.JOBS, key=msg.request.document_id, value=msg.to_json())

event = ResultEvent.model_validate_json(record.value())   # from Topics.RESULTS
```

## What is in it

| Message | Where it travels | Schema |
|---|---|---|
| `JobRequest` | Body of `POST /jobs` | [`job-request`](qaechi/contracts/schemas/v1/job-request.schema.json) |
| `JobMessage` | Kafka `qaechi.parse.jobs`, key `documentId`. Any system may publish one, for example a transactional outbox | [`job-message`](qaechi/contracts/schemas/v1/job-message.schema.json) |
| `ResultEvent` | Kafka `qaechi.parse.results`, key `documentId`. One per finished job | [`result-event`](qaechi/contracts/schemas/v1/result-event.schema.json) |
| `Extraction` | `GET /results/{id}`: values with quote and page | [`extraction`](qaechi/contracts/schemas/v1/extraction.schema.json) |

Headers: `traceparent` (W3C trace context) on every message, `qaechi-error` on DLQ copies.
Default topics are in `Topics`; every module lets you rename them.

## Compatibility rules

- Every message carries `specVersion`. This is version **1**.
- Within a major version fields are only **added**, and only as optional. Readers ignore fields
  they do not know, so an older consumer keeps working with a newer producer.
- A breaking change means `specVersion: "2"`, a new major release of this package, and a period
  in which qaechi modules read both.
- **The major version of qaechi-contracts is the compatibility line.** Servers and clients that
  share it can be upgraded independently.

CI checks every change two ways: the committed JSON Schemas must match the models, and the latest
released `qaechi-parser` must produce messages that validate against them.

## Other languages

The JSON Schemas (draft 2020-12) are the source for other languages. Generate types with your
usual tool, for example `quicktype` or `datamodel-code-generator`. Java (`io.github.qaechi:qaechi-contracts`)
and TypeScript (`@qaechi/contracts`) packages are planned.

## License

Apache-2.0. See [LICENSE](LICENSE).
