Metadata-Version: 2.4
Name: libwhelk
Version: 1.0.0
Summary: Whelk's core over its C ABI: the event fold, pairing codes and slash commands.
License-Expression: Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# `libwhelk` for Python

A `ctypes` binding over `libwhelk`, the stable C ABI on `whelk-core`. **No
dependencies**: `ctypes` is in the standard library.

Install the distribution `libwhelk`; the import stays `whelk` (the plain `whelk`
name on PyPI is an unrelated package):

```
pip install libwhelk
```

```python
import whelk

whelk.version()                 # the core this library wraps
whelk.parse_command("/loop 20")
whelk.decode_pairing_code(raw)
whelk.fold_event_log([(timestamp_ms, event_json), ...])
```

## Finding the library

`WHELK_LIBRARY` first, then beside the package, then the workspace's
`target/{release,debug}`, then the platform loader. So a checkout works with
nothing installed:

```sh
cargo build --manifest-path libwhelk/Cargo.toml
PYTHONPATH=libwhelk/python python3 -c "import whelk; print(whelk.version())"
```

## What it is not

It is **not a second implementation**. Every call marshals bytes across the
boundary and hands back what Rust decided: no fold, no decoder and no command
table is written in Python.

It **does not open the record**. The encrypted event log is SQLCipher keyed from
a platform secret store, and a binding that opened it would be a second answer
to where a person's data lives. Feed it events you have already read.

## Tests

Every case loads the real library and calls it; nothing is mocked, because the
boundary is the whole of what this package is.

```sh
cargo build --manifest-path libwhelk/Cargo.toml
python3 libwhelk/python/tests/test_whelk.py
```

## Partner SDK

`whelk.partner` is a separate, HTTP-only client for a third-party app that runs
inference on the Whelk Server its user runs. It carries no FFI and needs no
compiled library: it discovers the server, carries a partner grant as the bearer
token, and calls `/v1/*`.

```python
from whelk.partner import Partner

partner = Partner("http://192.168.1.10:8080", grant)  # grant from `whelk partner grant`
partner.capabilities()                                # GET /.well-known/whelk
partner.models()                                      # the models the grant may call
partner.chat("local/qwen2.5-coder", messages)
```

It **never routes inference anywhere but the server the user runs**. With no
server address it raises `WhelkServerUnavailable`, the hard "no runtime" error,
rather than reaching a cloud provider of its own.
