Repository navigation
Conversation
Turn the proof-of-concept project into the `clairic` package: hatchling build with a src layout, Python 3.10+, httpx and pydantic dependencies, ruff, pyright in strict mode, pytest, and a CI workflow running all checks on Python 3.10 to 3.14. Add the MIT license, a NOTICE crediting the Cloudflare documentation (CC BY 4.0) and the unofficial disclaimer. main.py is removed here because this commit drops the `requests` dependency it relies on; examples/invoice.py replaces it in S8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Answer models cover every Clairic response shape: text, number, date, time, datetime, duration, text lists, number and date lists, numeric and date estimates, and forecasts. Shapes and semantics come from responses recorded against the live API on 2026-10-25, now stored under tests/fixtures/responses (account id redacted). response.json moves there as invoice.json. errors.py defines the exception hierarchy and ClairicTruncationWarning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Specs carry the options of each Clairic field type and attach to answer types through Annotated. Constructors reject every option value the live API rejected during probing (bounds, decimals, horizon, null threshold, log scale minimum, steps, duration units), so a mistake surfaces where the model is declared. pytest now also runs the doctests in src. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compiler turns a Pydantic model whose fields are answer types into the Clairic `fields` object and reads the answers back into the model. The answer type picks the Clairic field type and implies `integer` and list `items`; an Annotated spec adds options; Field(description=...) becomes the instructions; an alias becomes the Clairic field name. Invalid models raise ModelDefinitionError naming the field, before any request. Compiled payloads are cached per model class. tests/typing holds assert_type checks that pyright enforces, including attribute accesses that must stay type errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Result[M] holds the extraction model, token usage, the truncation flag and the request id. It round-trips through JSON, including models with aliased fields, which are dumped under their Clairic names. values_as(Target) copies each answer value into the same-named field of a plain-values model and lets Pydantic validate it. Usage documents that input tokens count the state once per pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Clairic and AsyncClairic post an extraction model to the Workers AI REST endpoint and return a Result. Credentials fall back to CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN. Cloudflare error responses map to typed exceptions carrying the status, error code and request id; transport failures map to APIConnectionError and APITimeoutError; a truncated result emits ClairicTruncationWarning at the caller. Invalid models and empty states fail before any request. The package now exports its public API, and the version lives in _version.py, read by hatch and sent in the User-Agent header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/live extracts every field type, estimates, a forecast and an authentication error against the real API; they run with `pytest -m live` when CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN are set (a local .env is loaded) and are deselected otherwise. scripts/check_schema_drift.py diffs Cloudflare's published input and output schemas against the copies vendored in tests/fixtures/schemas; a weekly workflow runs it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The README covers installation, credentials, declaring fields with answer types and specs, reading answers and their metadata, the values export, storing results, the async client, errors, cost per pass, and development commands. examples/invoice.py runs the reference invoice extraction end to end and replaces the former main.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the repository, issues and Clairic reference links shown on the PyPI project page, and run CI on pushes to version branches (v*), where each release line lives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What it does
First release of
clairic, an unofficial typed Python SDK for Cloudflare Clairic. A user declares a Pydantic model whose fields are Clairic answer types, callsClairic().extract(text, Model), and gets aResultholding each value with its metadata (confidence, probability of absence, spans, percentiles).Annotatedspecs; specs reject the option values the live API rejects, before any request.Clairicand asyncAsyncClairicclients; Cloudflare errors map to typed exceptions with status, code and request id.Result.values_as(PlainModel)exports plain values; results round-trip through JSON.NOTICE).Answer shapes, accepted options and error codes come from 54 requests recorded against the live API on 2026-10-25, stored under
tests/fixtures/responses.One commit per step: packaging, answers and errors, specs, compiler, result, clients, live tests and schema drift check, README and example, release metadata.
How to test
Locally: 98 offline tests and 5 live tests pass on Python 3.14 and 3.10.
🤖 Generated with Claude Code