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

# Python SDK Overview

> Install, configure, and choose the right Python SDK surface.

Install the SDK into a Python 3.11+ environment. The CLI extra gives you
`nullspace auth login` for local credential setup:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
python -m pip install "nullspace-sdk[cli]==1.0.0"
```

For local interactive use, save the API endpoint and key:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
nullspace auth login --api-url https://api.13-215-85-171.sslip.io
```

For a self-hosted single-host appliance in localhost/no-domain mode:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
export NULLSPACE_API_KEY="$(sudo cat /etc/nullspace/operator-api-key)"
export NULLSPACE_API_URL=http://localhost
```

For owned-domain appliance mode, use your Caddy/API origin:

```bash theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
export NULLSPACE_API_URL=https://nullspace.example
```

For scripts, CI, and coding agents, you can still set `NULLSPACE_API_KEY` and
`NULLSPACE_API_URL` as environment variables.

## Core imports

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
from nullspace import Machine, Template, Volume
```

Use `Machine` for live runtime work, `Template` for reusable environments, and
`Volume` for persistent shared filesystems on volume-enabled deployments.

## First machine

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
from nullspace import Machine

with Machine.create(template="base") as machine:
    result = machine.commands.run("python3 --version", shell=True)
    print(result.stdout.strip())
```

The SDK accepts explicit `api_key=` and `base_url=` arguments. SDK and CLI share configuration precedence:
environment variables, project `.env`, `~/.config/nullspace/config.json`, then
legacy `~/.nullspace/config.json`.
`nullspace auth login --api-url ...` still writes the legacy path for backward
compatibility.
See [SDK Config](../../reference/config).

Concepts: [Create](../../concepts/create), [Exec](../../concepts/exec). API
reference: [createMachine](../../api-reference), [execCommand](../../api-reference).
Self-hosted setup: [Self-Hosted Single-Host](../../quickstarts/self-hosted-single-host).
