Metadata-Version: 2.5
Name: holon-om
Version: 0.0.26
Summary: In-process Python bindings for holon-sh/om via WebAssembly (compile and serve OpenAPI & GraphQL APIs as MCP servers without subprocesses).
License: MIT
Requires-Python: >=3.10
Requires-Dist: wasmtime>=25.0.0
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# holon-om (Python)

In-process Python bindings for [`holon-sh/om`](https://github.com/holon-sh/om), powered by a single portable WebAssembly (`wasip1/wasm`) reactor running under `wasmtime`.

## Build the WASM module

From the repository root (requires Go 1.27+):

```sh
./scripts/build-wasm.sh
```

This builds `build/om.wasm` (used automatically in-tree, or pass `bindings/python/src/om/_om.wasm` when building a standalone wheel).

## Usage

### OpenAPI

```python
import os
import om
from om import discover

offers = discover.offers("https://api.example.com")
data, location = discover.get(offers[0].url)

compiled = om.compile_openapi(data, location=location)
model = compiled.document.to_json()

with om.Document.from_json(model) as doc:
    page = doc.tools()
    result = doc.call_tool("list_widgets", {"limit": 10}, inputs=os.environ)
```

### Async & Streamable HTTP MCP

Every I/O operation has an `*_async` counterpart (`compile_openapi_async`, `call_tool_async`, `handle_mcp_async`, `introspect_async`, `discover.offers_async`, `discover.get_async`) that releases the WASM lock across `await` and accepts any `AsyncTransport`. If you already use `httpx`, pass `om.httpx_async_transport(client)` (or `om.httpx_transport(client)` for sync) — redirects are always disabled per request so `om`'s redirect rules apply:

```python
import httpx

async with httpx.AsyncClient() as client:
    resp = await doc.handle_mcp_async(
        method="POST",
        headers=request_headers,
        body=request_body,
        inputs=os.environ,
        transport=om.httpx_async_transport(client),
    )

    # For SSE event streams (events/stream), use handle_mcp_stream_async:
    async with await doc.handle_mcp_stream_async(
        method="POST",
        headers=sse_headers,
        body=sse_body,
        inputs=os.environ,
        transport=om.httpx_async_stream_transport(client),
    ) as stream:
        async for chunk in stream:
            ...
```

### GraphQL

```python
import os
import om

schema = om.introspect(
    "https://api.github.com/graphql",
    credential=om.BearerToken(),
    inputs=os.environ,
)
compiled = om.compile_graphql(
    "https://api.github.com/graphql",
    schema,
    {"viewer.graphql": viewer_query_bytes},
    credential=om.BearerToken(),
)
```
