# 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.PackageCommands

*class* · *dataclass*

```python
class PackageCommands
```

Re-exported from: `ocx_sdk._client`

The `ocx package` command group — machine tier.

Package operations act on the `$OCX_HOME` store and its candidate and
current symlinks. They take no project path and are CWD-independent by
construction; a path appears only where the CLI itself takes one.

Every method is multi-identifier native, mirroring the CLI's `PKG...`
with one shared resolution.

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

### ocx_sdk.PackageCommands.spawn_async

*method* · *async*

```python
async def spawn_async(refs: Sequence[PackageLike], argv: Sequence[str], *, platform: str | None = None, clean: bool = False, private: bool = False, env: Mapping[str, EnvValue] | None = None, lazy_mode: LazyMode | None = None, records_dir: str | Path | None = None, records_name: str | None = None, **popen_kw: Any) -> asyncio.subprocess.Process
```

Start a command in a packages' environment, on the event loop.

**Parameters**

- `refs` (`Sequence[PackageLike]`) — Package identifiers to compose.
- `argv` (`Sequence[str]`) — The command and its arguments. Must not be empty.
- `platform` (`str | None`) (default: `None`) — The platform to resolve against.
- `clean` (`bool`) (default: `False`) — Strip the ambient parent environment before composing.
- `private` (`bool`) (default: `False`) — Compose the private surface — ocx's `--self`.
- `env` (`Mapping[str, EnvValue] | None`) (default: `None`) — Extra `[env]` entries for this call.
- `lazy_mode` (`LazyMode | None`) (default: `None`) — When content downloads — now, or on first use.
- `records_dir` (`str | Path | None`) (default: `None`) — Write an execution record — the resolved closure and executable — under this directory. `None` leaves it to `[records] dir` and `OCX_RECORDS_DIR`; with none of the three, no record is written.
- `records_name` (`str | None`) (default: `None`) — The record's filename template, over `{time}`, `{host}`, `{pid}` and `{rand}`. `None` leaves it to `[records] name` and `OCX_RECORDS_NAME`.
- `**popen_kw` (`Any`) (default: `{}`) — Forwarded to the subprocess factory. `args`, `shell`, and `executable` are rejected.

**Returns**

- (`asyncio.subprocess.Process`) — The running child.

**Raises**

- `ValueError` — `argv` is empty, or a rejected keyword was passed.

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

### ocx_sdk.PackageCommands.uninstall

*method*

```python
def uninstall(*refs: PackageLike, deselect: bool = False, purge: bool = False, timeout: MaybeTimeout = UNSET, retry: MaybeRetry = UNSET) -> tuple[RemovalResult, ...]
```

Remove installed candidates.

**Parameters**

- `*refs` (`PackageLike`) (default: `()`) — Package identifiers.
- `deselect` (`bool`) (default: `False`) — Also drop the `current` symlink.
- `purge` (`bool`) (default: `False`) — Delete the object from the store once nothing references it.
- `timeout` (`MaybeTimeout`) (default: `UNSET`) — Seconds per attempt. Omitted takes the config's.
- `retry` (`MaybeRetry`) (default: `UNSET`) — Retry policy. `None` opts out; omitted takes the config's.

**Returns**

- (`tuple[RemovalResult, ...]`) — One row per removal.

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