# ocx_sdk

*module*

Python SDK for [OCX](https://github.com/ocx-sh/ocx).

`ocx-sdk` drives the ocx binary rather than reimplementing it: ocx owns
resolution, verification, and the identifier grammar, and this package gives
you typed, CWD-independent handles over the commands it exposes.

```python
from ocx_sdk import Ocx, bootstrap

ocx = Ocx(exe=bootstrap.ensure())
project = ocx.project("/srv/build")
project.pull()
project.exec(["task", "verify"])
```

**This module is the API.** Everything listed in `__all__` is the stable
surface; every other module is underscored and package-private, and the one
public submodule is `ocx_sdk.bootstrap`. Reaching into an underscored path
means the next release may move it without notice — pre-1.0, breaking
changes ship without shims.

Start at `Ocx` for the runtime API and `bootstrap.ensure` for provisioning.

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/__init__.py#L1-L1)

## ocx_sdk.ErrorEnvelope

*class* · *dataclass*

```python
class ErrorEnvelope
```

Re-exported from: `ocx_sdk._results`

The structured failure ocx prints under `--format json` (C-S1-1).

`{schema_version, command, exit_code, error: {kind, detail?, message,
remediation?, context}}` — a contract frozen separately from the reports
schema, and printed on stdout only when the failing command wrote no
report of its own. `error_envelope(err)` is how a caller reaches it.

The exit code is still the category (`_errors`): `kind` restates it as
ocx's own vocabulary, and `detail` — when present — is the fine-grained
slug to branch on. `message` is prose, free to be reworded.

**Attributes**

- `schema_version` (`int`) — The envelope's own version; `1` for every 0.6 binary.
- `command` (`str`) — The canonical command string, e.g. `"package claim"`.
- `exit_code` (`int`) — The exit status the process returned.
- `kind` (`str`) — The coarse category, snake_case (`"data_error"`, `"auth_error"`, ...).
- `message` (`str`) — The outermost message of the error chain.
- `detail` (`str | None`) — The fine-grained variant slug, when ocx assigned one.
- `remediation` (`str | None`) — A remediation hint. Reserved upstream and never emitted by a 0.6 binary; carried so a consumer treating it as optional keeps working when it appears.
- `context` (`Mapping[str, Any]`) — Structured context (identifiers, digests, URLs), untyped.

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L329-L377)

### ocx_sdk.ErrorEnvelope.detail

*attribute* · *class attribute* · *instance attribute*

```python
detail: str | None = None
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L360-L360)

### ocx_sdk.ErrorEnvelope.exit_code

*attribute* · *instance attribute*

```python
exit_code: int
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L357-L357)

### ocx_sdk.ErrorEnvelope.kind

*attribute* · *instance attribute*

```python
kind: str
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L358-L358)

### ocx_sdk.ErrorEnvelope.message

*attribute* · *instance attribute*

```python
message: str
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L359-L359)

### ocx_sdk.ErrorEnvelope.remediation

*attribute* · *class attribute* · *instance attribute*

```python
remediation: str | None = None
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L361-L361)

### ocx_sdk.ErrorEnvelope.schema_version

*attribute* · *instance attribute*

```python
schema_version: int
```

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L355-L355)

### ocx_sdk.ErrorEnvelope.from_dict

*method* · *classmethod*

```python
def from_dict(data: Mapping[str, Any]) -> ErrorEnvelope
```

Build from a decoded envelope, reading across its two levels.

[View source](https://github.com/ocx-sh/ocx-sdk-python/blob/main/src/ocx_sdk/_results.py#L364-L377)
