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

*class* · *dataclass*

```python
class Project
```

Re-exported from: `ocx_sdk._client`

A project-tier handle: every call carries `--project <file>`.

Obtained from `Ocx.project(path)`, never constructed directly. Because
the path travels explicitly on every call, no method depends on the
working directory, and an ambient `OCX_PROJECT` can never retarget one.
`init` is the exception, and only because ocx's is: it takes no flags and
writes into the working directory, so the handle sets that instead.

> **Example**
>
> ```python
> from ocx_sdk import Ocx
> 
> project = Ocx().project("/srv/build")
> project.add("ocx.sh/go-task/task:3", group="ci")
> project.lock()
> report = project.env()
> environment = report.compose().mapping
> ```

**Attributes**

- `path` (`Path`) — The absolute project file — the `ocx.toml` itself, which is what ocx's `--project` names.
- `session_config` (`OcxConfig`) — The `OcxConfig` every call spawns under.

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

### ocx_sdk.Project.exec_async

*method* · *async*

```python
async def exec_async(argv: Sequence[str], *, names: Iterable[str] = (), groups: Iterable[str] = (), clean: bool = False, env: Mapping[str, EnvValue] | None = None, lazy_mode: LazyMode | None = None, pinned: bool | None = None, records_dir: str | Path | None = None, records_name: str | None = None, capture: bool = True, check: bool = True, timeout: MaybeTimeout = UNSET) -> CommandResult
```

Run a command in the project's environment, on the event loop.

**Parameters**

- `argv` (`Sequence[str]`) — The command and its arguments. Must not be empty.
- `names` (`Iterable[str]`) (default: `()`) — Bindings to compose.
- `groups` (`Iterable[str]`) (default: `()`) — Groups to compose.
- `clean` (`bool`) (default: `False`) — Strip the ambient parent environment before composing.
- `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.
- `pinned` (`bool | None`) (default: `None`) — Resolve through pinned digests — see `exec`.
- `records_dir` (`str | Path | None`) (default: `None`) — Write an execution record here — see `exec`.
- `records_name` (`str | None`) (default: `None`) — The record's filename template — see `exec`.
- `capture` (`bool`) (default: `True`) — Pipe and capture both streams.
- `check` (`bool`) (default: `True`) — Raise on a non-zero child exit instead of returning it.
- `timeout` (`MaybeTimeout`) (default: `UNSET`) — Seconds for the whole run. Omitted takes the config's.

**Returns**

- (`CommandResult`) — The child's exit code and, under `capture`, its output.

**Raises**

- `ValueError` — `argv` is empty, or the handle carries an `on_log`
callback, which v0.1 refuses on async paths.
- `OcxProcessError` — The child exited non-zero under `check`.
- `OcxTimeoutError` — The timeout expired.

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

### ocx_sdk.Project.spawn

*method*

```python
def spawn(argv: Sequence[str], *, names: Iterable[str] = (), groups: Iterable[str] = (), clean: bool = False, env: Mapping[str, EnvValue] | None = None, lazy_mode: LazyMode | None = None, pinned: bool | None = None, records_dir: str | Path | None = None, records_name: str | None = None, **popen_kw: Any) -> subprocess.Popen[Any]
```

Start a command in the project's environment and return `Popen`.

**Parameters**

- `argv` (`Sequence[str]`) — The command and its arguments. Must not be empty.
- `names` (`Iterable[str]`) (default: `()`) — Bindings to compose.
- `groups` (`Iterable[str]`) (default: `()`) — Groups to compose.
- `clean` (`bool`) (default: `False`) — Strip the ambient parent environment before composing.
- `env` (`Mapping[str, EnvValue] | None`) (default: `None`) — Extra `[env]` entries for this call, not the child's environment — that one is SDK-composed.
- `lazy_mode` (`LazyMode | None`) (default: `None`) — When content downloads — now, or on first use.
- `pinned` (`bool | None`) (default: `None`) — Resolve through pinned digests — see `exec`.
- `records_dir` (`str | Path | None`) (default: `None`) — Write an execution record here — see `exec`.
- `records_name` (`str | None`) (default: `None`) — The record's filename template — see `exec`.
- `**popen_kw` (`Any`) (default: `{}`) — Forwarded to `Popen`. `args`, `shell`, and `executable` are rejected.

**Returns**

- (`subprocess.Popen[Any]`) — 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#L1355-L1393)
