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

# Automate Infrastructure with the Nodepick Python SDK

> Install and use the Nodepick Python SDK to create, inspect, and delete compute nodes programmatically. Includes full working code examples.

The Nodepick Python SDK gives you a clean, Pythonic interface for provisioning and managing isolated Linux kernel nodes directly from your code. Whether you're spinning up ephemeral compute for a CI pipeline, a data processing job, or an AI workload, the SDK handles the API calls so you can focus on what runs on the node.

## Installation

Install the `nodepick` package from PyPI using pip:

```bash theme={null}
pip install nodepick
```

## Initialization

Import the `nodepick` class and instantiate a client with your API key:

```python theme={null}
from nodepick import nodepick

client = nodepick(api_key="YOUR_API_KEY")
```

### Using Environment Variables (Recommended)

Avoid hardcoding your API key in source files. Instead, read it from an environment variable:

```python theme={null}
import os
from nodepick import nodepick

client = nodepick(api_key=os.environ["NODEPICK_API_KEY"])
```

Set the variable in your shell before running your script:

```bash theme={null}
export NODEPICK_API_KEY="YOUR_API_KEY"
```

## Core Operations

<Steps>
  <Step title="Create a Node">
    Call `create_node()` to provision a new Linux kernel node. The method returns a dictionary containing the node's `id`, `status`, and other metadata:

    ```python theme={null}
    node = client.create_node()
    node_id = node["id"]
    print(f"Node created: {node_id}")
    print(f"Status: {node['status']}")
    ```
  </Step>

  <Step title="Get Node Details">
    Once provisioning is complete, retrieve the node's full details — including its IP address and SSH connection info — using `get_node_details()`:

    ```python theme={null}
    details = client.get_node_details(node_id)
    print(f"IP Address: {details['ip_address']}")
    print(f"SSH: ssh root@{details['ip_address']}")
    ```
  </Step>

  <Step title="Delete a Node">
    When you're finished with a node, delete it to immediately stop billing:

    ```python theme={null}
    client.delete_node(node_id)
    print("Node deleted")
    ```
  </Step>
</Steps>

## Using the Context Manager

The `nodepick` client supports Python's context manager protocol, which automatically calls `client.close()` when the `with` block exits — even if an exception is raised.

```python theme={null}
from nodepick import nodepick

with nodepick(api_key="YOUR_API_KEY") as client:
    node = client.create_node()
    node_id = node["id"]

    details = client.get_node_details(node_id)
    print(f"SSH: ssh root@{details['ip_address']}")

    # Cleanup
    client.delete_node(node_id)
# Client is automatically closed
```

<Note>
  The context manager calls `client.close()` automatically when the `with` block exits. You do not need to call it manually when using this pattern.
</Note>

## Complete Workflow Example

The following script demonstrates a full end-to-end lifecycle: creating a node, waiting for it to be ready, retrieving its connection details, performing work, and then cleaning up.

```python theme={null}
import os
from nodepick import nodepick

# Initialize the client using an environment variable
with nodepick(api_key=os.environ["NODEPICK_API_KEY"]) as client:

    # Step 1: Provision a new node
    print("Creating node...")
    node = client.create_node()
    node_id = node["id"]
    print(f"Node created: {node_id} (status: {node['status']})")

    # Step 2: Retrieve connection details once the node is running
    details = client.get_node_details(node_id)
    ip = details["ip_address"]
    print(f"Node is running at {ip}")
    print(f"Connect with: ssh root@{ip}")

    # Step 3: Do your work here
    # e.g. run remote commands via paramiko, subprocess, or fabric

    # Step 4: Delete the node to stop billing
    client.delete_node(node_id)
    print(f"Node {node_id} deleted. Billing stopped.")

# client.close() is called automatically here
```

<Tip>
  Always delete nodes as soon as your workload completes. Nodepick bills per second from the moment a node is created until it is deleted. Leaving nodes running unnecessarily will result in unexpected charges.
</Tip>
