> ## Documentation Index
> Fetch the complete documentation index at: https://www.offlineprotocol.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> These docs target Mesh SDK v0.32.0. Match the installed package and binding before generating code. Start at /getting-started/agents for task-specific reading paths. Apps that call enableTelemetry on 0.26.0 to 0.29.0 should update to 0.30.0 or later: the telemetry uploader trusts only the telemetry endpoint's issuing roots from 0.30.0.
> Call the company and product Offline Protocol, never Offline alone. Current packages: @offline-protocol/mesh-sdk 0.32.0 (React Native), offline-protocol-sdk 0.32.0 on PyPI (Python 3.10 to 3.13; wheels for macOS 14+ arm64, Linux x86_64 and aarch64 with glibc 2.34+, Windows x86_64; other hosts build from source; extras lan and http add LAN discovery, the HTTP front and offline-protocol-verify), the offline-protocol crates 0.32.0 on crates.io, the OfflineProtocolSDK Swift package 0.32.0 (preview, iOS 13+ only), the Android library com.offlineprotocol:offline-protocol-sdk 0.32.0 on Maven Central (preview, minSdk 24), the Java binding com.offlineprotocol:offline-protocol-java 0.32.0 on Maven Central (JDK 22+, native library from the GitHub release's desktop archives), the C header offline_protocol.h with the native library in the GitHub release's desktop archives, the Ruby binding offline_protocol 0.32.0 on RubyGems (Ruby 3.3+, native library from the GitHub release's desktop archives), the C# binding (preview, .NET 8; source in bindings/csharp in the SDK repository at tag v0.32.0, a project reference over the C API, not on NuGet), the browser binding (experimental; the offline-protocol-web crate 0.32.0 on crates.io, with the JavaScript in bindings/web built from the SDK repository, not on npm), the offline_protocol Flutter plugin (preview, not on pub.dev; a path dependency on the SDK repository at tag v0.32.0; MeshSdk carries the React Native module's native surface), the service container image ghcr.io/offline-protocol/offline-protocol-service 0.32.0 (linux/amd64 and linux/arm64), @offline-protocol/id-react 0.3.0, @offline-protocol/id-react-native 0.4.0, @offline-protocol/pol 0.1.2 and @offline-protocol/cli 0.3.2 (account setup commands such as offline apps status, offline apps native and offline apply since 0.3.0). Canonical docs URLs start with https://www.offlineprotocol.com/docs.
> The Mesh SDK runs in a native app or gateway, and from 0.31.0 in a browser through the experimental browser binding (a full node in a Web Worker; see /mesh-sdk/web). The OfflineID SDK for React does not provide browser mesh transport. Local mesh operation does not require a portal account or API key. The Mesh SDK appId is a mesh app identifier the developer chooses, not the portal App ID (app_...) that OfflineID and Proof of Location require.
> In v0.32.0 service RPC bodies are sealed in the 1:1 MLS session once the recipient runs 0.29 or later and the session is confirmed; discovery, the first request to a provider never met, and requests to older peers are signed plaintext, so keep secrets out of service bodies unless the event says encrypted: true. Service subscriptions (subscribeService, publishServiceUpdate, from 0.32.0) are always sealed in the 1:1 MLS session with no plaintext fallback; under the default restricted policy the provider app must answer service_subscribe_received with acceptServiceSubscription or rejectServiceSubscription within 60 seconds. Content that begins with __MEMBER__ is a reserved prefix and is refused. The HTTP front (offline-protocol-service --http) always carries calls inside encrypted direct messages but does not authorize callers. Message delivery, durable local acceptance and backend commit are distinct outcomes. Use the workflow guide for the required application logic.
> Offline Protocol CLI 0.3.2 is on npm (@offline-protocol/cli, command offline). Its local MCP server, named offline-protocol, runs with npx -y @offline-protocol/cli@0.3.2 mcp serve and requires no login or key. Hosted MCP is at https://mcp.offlineprotocol.com/mcp with an app API key in Authorization: Bearer and the matching App ID in x-app-id; organization keys are rejected, and Claude Desktop and Claude.ai cannot send these headers; there, use the public read-only endpoint https://mcp.offlineprotocol.com/public/mcp as a custom connector, or local MCP to scaffold or edit projects. Follow /tools/overview for setup and do not invent commands beyond it. MCP provides integration context and planning, not mesh execution; file-writing tools are local only.
> In v0.32.0 phone Wi-Fi peer streams carry data: Android over Wi-Fi Direct (the SDK forms the group with autoAccept on Android 10+) and over the Wi-Fi network it is on (DNS-SD), iOS over Network framework (LAN or AWDL). Android and iOS meet over that slot only on a shared Wi-Fi network that allows multicast; iOS 0.28 and later does not see iOS 0.27 or earlier over it. Otherwise use BLE or a provisioned relay across platforms. The Swift and Android packages are previews; the Android library is on Maven Central from 0.29.0 only, so never give a Gradle line for an earlier version. The receiver core ACKs before application persistence; use application acceptance for durable workflows.
> OfflineID App IDs are public. A request naming an application needs a credential: an allowed browser origin, an API key in X-Api-Key from a server, or, from an iOS or Android app, an attestation from a build registered to the application (iOS bundle ID and Team ID, Android package and signing certificate SHA-256). Register native apps with offline apps native add or offline apply, pass attestation providers (createExpoAppIntegrityProviders with @expo/app-integrity) to OfflineAppProvider, sign in on a physical device, and check readiness with offline apps status. Follow /getting-started/agent-quickstart and /id-sdk/app-attestation; error responses list the fixing commands in data.next_steps.
> Proof of Location is Sepolia testnet witness evidence, not zero-knowledge proof or proof of presence. The geohash is public onchain. Read /proof-of-location/security before integration.

# Python and Linux gateways

> Install the Mesh SDK v0.32.0 Python package from PyPI and run a full Offline Protocol peer on a Linux or desktop gateway over local IP, with persistent state.

The Python binding supports desktop and gateway processes. Its peer-stream transport uses TCP over an existing IP network; it does not create a Wi-Fi Direct network. Internet relay and BLE integrations have separate platform requirements.

## Install from PyPI

```bash theme={null}
python3 -m venv .venv
. .venv/bin/activate
python -m pip install 'offline-protocol-sdk[lan]==0.32.0'
```

The package is `offline-protocol-sdk` and the import name is `offline_protocol_sdk`. It supports Python 3.10 to 3.13. The `lan` extra adds DNS-SD discovery for peer streams; leave it out if you configure peers by address. The `http` extra, from v0.29.0, adds the [HTTP front](https://www.offlineprotocol.com/docs/mesh-sdk/http-front.md); install both with `'offline-protocol-sdk[lan,http]==0.32.0'` for a host that runs the service. The package installs three commands: `offline-protocol-service`, `offline-protocol-http-front` and `offline-protocol-verify`.

PyPI has a wheel for each of these platforms, with the native library inside:

| Platform | Wheel tag |
| - | - |
| macOS 14 or later on Apple silicon (arm64) | `macosx_14_0_arm64` |
| Linux x86\_64 with glibc 2.34 or later | `manylinux_2_34_x86_64` |
| Linux aarch64 with glibc 2.34 or later | `manylinux_2_34_aarch64` |
| Windows x86\_64 | `win_amd64` |

glibc 2.34 means Debian 12, Ubuntu 22.04, RHEL 9 or newer. There is no wheel for Intel macOS or for musl-based Linux such as Alpine, and no source distribution, so `pip` reports no matching distribution on those hosts. Build from source there.

The package metadata names AGPL-3.0-only. The SDK is dual-licensed, and a commercial license is available; see [licensing](https://www.offlineprotocol.com/docs/operations/licensing.md).

### Build from source

On a platform without a wheel, install the Rust toolchain (1.91 or newer) and the native build prerequisites for your OS, then build the native library and the bindings from the same revision:

```bash theme={null}
git clone --branch v0.32.0 --depth 1 https://github.com/Offline-Protocol/offline-protocol-sdk.git
cd offline-protocol-sdk
cargo install uniffi --version 0.32.2 --features cli --locked
cd bindings/python
bash scripts/build-desktop.sh
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[lan]'
```

Do not combine generated bindings from one revision with a native library from another.

## Choose the storage

The SDK keeps two things on disk: the MLS store, which holds this device's identity and sessions, and the protocol state under `state_root`, which holds the outbox, pending queues and delivery state. Preserve both across restarts.

| Host | MLS store | Configure |
| - | - | - |
| Desktop with a secret service (macOS Keychain, GNOME Keyring or KWallet, Windows Credential Locker) | The OS keyring, through `keyring` | `state_root` |
| Server, container or any host without a secret service | The built-in sealed file store, under a store key you supply | `store_key_env` or `store_key`, `mls_root` and `state_root` |

On a headless Linux host, `keyring` falls back to a backend that cannot hold keys, and the SDK logs a warning naming it. Use the file stores there.

### Built-in file stores

Pass a store key and `ProtocolManager` uses the SDK's file stores instead of the keyring. Every MLS record is sealed on disk under that key.

```bash theme={null}
export OFFLINE_PROTOCOL_STORE_KEY="$(openssl rand -hex 32)"   # once; keep it
```

```python theme={null}
pm = ProtocolManager(
    config,
    event_handler=print,
    store_key_env="OFFLINE_PROTOCOL_STORE_KEY",  # 64 hex digits or base64
    mls_root="/var/lib/field-handoff/keys",      # or OFFLINE_PROTOCOL_MLS_ROOT
    state_root="/var/lib/field-handoff/state",   # or OFFLINE_PROTOCOL_STATE_ROOT
)
```

* The store key is 32 random bytes, generated once and kept. Hand it to the process the way your service manager hands it any secret, or pass `store_key=<bytes>`. Never derive it from a password or host name.
* `mls_root` holds this device's identity. Losing it gives the device a new address. Keep `mls_root` and `state_root` apart; the same directory, or one inside the other, is refused.
* Moving an existing keyring deployment onto the file stores starts a new identity. Point `state_root` at a fresh directory; a state directory written by another identity is refused with `ProtocolError.InvalidConfiguration`.
* `start()` raises instead of starting without an identity. A wrong key raises `ProtocolError.InvalidConfiguration` and changes no record. A directory another process holds raises `ProtocolError.InvalidState`.
* Each store locks its directory while open. `await pm.close()` stops the manager and releases both directories, and leaving `async with` does the same. Use `stop()` and `start()` to restart in place.

On a host without a keystore the store key sits wherever the process reads it from. The [release threat model](https://github.com/Offline-Protocol/offline-protocol-sdk/blob/v0.32.0/docs/security/threat-model.md) records this as residual risk R18.

## Start a local peer

Save this as `local_peer.py` and run it from the activated environment. Each host uses its own state directory and its own MLS store. Allow TCP port 7878 and DNS-SD on the local network, or configure an explicit peer endpoint instead of discovery.

```python theme={null}
import asyncio
from pathlib import Path
from offline_protocol_sdk import ProtocolManager
from offline_protocol_sdk.offline_protocol import ProtocolConfig, OverflowPolicy

config = ProtocolConfig(
    app_id="field-handoff",
    profile="gateway",
    ble_enabled=False,
    wifi_direct_enabled=True,
    internet_enabled=False,
    reticulum_enabled=False,
    nostr_enabled=False,
    prefer_online=False,
    initial_ttl=8,
    encryption_enabled=True,
    auto_key_exchange=True,
    store_pending=True,
    require_encryption=True,
    max_pending_per_peer=64,
    max_pending_global=4096,
    pending_ttl_ms=86_400_000,
    overflow_policy=OverflowPolicy.DROP_OLDEST,
)

async def main():
    state_root = Path.home() / ".local" / "share" / "field-handoff"
    async with ProtocolManager(config, event_handler=print, state_root=state_root) as pm:
        address = pm.local_address
        if not address:
            raise RuntimeError("Identity unavailable; check the configured keyring")
        print("Address:", address)
        if pm.peer_stream is None:
            raise RuntimeError("Peer-stream transport is disabled")
        pm.peer_stream.configure(
            listen_host="0.0.0.0",
            listen_port=7878,
            advertise=True,
            discover=True,
        )
        await pm.peer_stream.start()
        await asyncio.Event().wait()

asyncio.run(main())
```

This example uses the OS keyring. On a host without one, add the file-store arguments above to the `ProtocolManager` call.

Run it on both hosts. The event stream identifies discovered peers. Use the resulting address when calling `pm.send_message(peer_address, content)` in your application. Binding `0.0.0.0` listens on every interface; use a specific interface address when the host spans networks. To skip discovery, pass `peers=["off1...@10.0.0.7:7878"]` or a plain `"host:port"` to `configure`.

An iPhone running Mesh SDK 0.28.0 or later, and an Android phone running 0.29.0 or later, with the `wifiDirect` transport enabled, find a Python host on the same Wi-Fi network over this transport, when the network allows multicast. Android Wi-Fi Direct groups do not include the host.

## Add an internet relay

Enable `internet_enabled` and configure `pm.internet` with the provisioned relay URL. Call `pm.internet.set_auth_token(auth_token)` before `pm.internet.start()`. Without an explicit token, the v0.32.0 manager falls back to the profile string, which is forgeable and is not a production authentication policy. See [relay access](https://www.offlineprotocol.com/docs/getting-started/platforms.md#obtain-relay-access). A relay connection is an additional path; it does not replace local transport or automatically upload business records into your backend.

`ProtocolManager` builds its `InternetManager` for you. Code that constructs an `InternetManager` directly must pass `app_id=` from v0.28.0; it is keyword-only with no default.

## Publish and subscribe to services

From v0.32.0 the `Services` wrapper in `offline_protocol_sdk.services` carries [service subscriptions](https://www.offlineprotocol.com/docs/guides/nearby-service.md#subscribe-to-a-service) next to discovery and requests. A provider publishes to a topic of a service it registered, and a consumer on another device subscribes to it:

```python theme={null}
from offline_protocol_sdk.services import Services

services = Services(pm.protocol)

# Provider: register the service, let members of one group subscribe,
# and publish the current battery level.
services.register("fleet.v1", "1.0")
services.set_policy("fleet.v1", "rules", allow_groups=[fleet_group_id])
services.publish("fleet.v1", "car", "81", key="battery")

# Consumer: follow two keys of the provider's latest state.
sub_id = services.subscribe(provider_address, "fleet.v1", "car", mode="latest", keys=["battery", "tyres.*"])
```

Updates arrive as `service_update_received` events and state changes as `service_subscription_changed`. Every subscription frame is sealed in the 1:1 MLS session.

## Serve several local applications

A single process can own the engine and serve several local applications over the [local API](https://www.offlineprotocol.com/docs/mesh-sdk/local-api.md). The package ships the reference server as the `offline-protocol-service` command. From v0.29.0 it starts every transport its configuration enables, and with `--http` it serves the [HTTP front](https://www.offlineprotocol.com/docs/mesh-sdk/http-front.md) for applications that do not use the SDK.

When one instance sends for several applications without the local API, stamp a per-send application id with `send_message_rich`:

```python theme={null}
from offline_protocol_sdk.offline_protocol import SendMessageOptions

message_id = pm.protocol.send_message_rich(
    peer_address,
    "door 4 cleared",
    SendMessageOptions(app_id="field-handoff.doors"),
)
```

The id changes the stamp on that message only, never the storage namespace or the MLS session. `message_received` carries `app_id` on the receiving side. It is cleartext and unsigned, so route on it and never authorize on it. An invalid id raises `ProtocolError.InvalidArgument` before anything is queued.

## Other transports

`wifi_direct_enabled=True` enables the existing-IP peer-stream slot. Python BLE uses `bleak` for central and `bless` for peripheral. `bless` is installed by default except on Windows; the SDK starts the peripheral when BLE is enabled. From v0.29.0 the peripheral serves the optional Hello characteristic and binds each central to the address its hello proves, on BlueZ and on macOS, so an Android phone, and an iPhone on 0.29.0, can start a session with the host over Bluetooth LE. It has been run between an Android phone and Macs and Raspberry Pis. Qualify platform radio support and permissions.

With `reticulum_enabled=True`, `pm.gateway` is a client for the [gateway-daemon contract](https://github.com/Offline-Protocol/offline-protocol-sdk/blob/v0.32.0/docs/spec/gateway-contract.md). Call `pm.gateway.configure(daemon_address="localhost:4242")` and `await pm.gateway.start()` after `pm.start()`. The daemon is deployed separately; see [Reticulum and Nostr](https://www.offlineprotocol.com/docs/mesh-sdk/reticulum-nostr.md).

See the [Python package README](https://github.com/Offline-Protocol/offline-protocol-sdk/tree/v0.32.0/bindings/python) and the [upgrade guide](https://www.offlineprotocol.com/docs/operations/upgrades.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.