Agent-friendly CLI for OctoPrint 3D printer management
Project description
octoprint-cli
Agent-friendly command-line interface for OctoPrint 3D printer management.
Designed for autonomous AI agent interaction with structured JSON outputs, clear exit codes, and safety guards for unattended operation.
Installation
pip install .
Or in development mode:
pip install -e ".[dev]"
Quick Start
1. Initialize configuration
octoprint-cli init
# Prompts for host URL and API key, saves to ~/.octoprint-cli/config.yaml
2. Or use environment variables
export OCTOPRINT_HOST="http://octopi.local"
export OCTOPRINT_API_KEY="your_api_key_here"
3. Check printer status
octoprint-cli status --json
Commands
| Command | Description |
|---|---|
status |
Get printer state, temperatures, and job progress |
files |
List available G-code files on the printer |
upload <file> |
Upload a G-code file |
print <file> |
Upload and start printing (requires --confirm) |
cancel |
Cancel current print (requires --confirm) |
pause |
Pause current print |
resume |
Resume paused print |
preflight [file] |
Run pre-flight safety checks |
temp |
Get or set temperatures |
gcode <cmds> |
Send raw G-code commands |
connect |
Connect printer to OctoPrint |
disconnect |
Disconnect printer from OctoPrint |
init |
Create configuration file |
Agent-Friendly Design
Structured JSON Output
Every command supports --json for machine-parseable output:
octoprint-cli status --json
{
"status": "success",
"data": {
"state": "Operational",
"temperature": {
"tool0": {"actual": 22.5, "target": 0.0},
"bed": {"actual": 21.8, "target": 0.0}
},
"job": {
"file": null,
"completion": null,
"print_time_left": null
}
}
}
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Printer offline / unreachable |
2 |
File error (not found, invalid format) |
3 |
Printer busy (already printing) |
4 |
Other error (auth, server, validation) |
Safety Flags
Destructive operations require explicit confirmation:
# Will fail without --confirm
octoprint-cli print model.gcode --confirm --json
# Cancel with confirmation
octoprint-cli cancel --confirm --json
Idempotent Operations
# Exits 0 if already printing instead of erroring
octoprint-cli print model.gcode --confirm --skip-if-printing --json
Configuration
Configuration is resolved with this precedence (highest first):
- CLI flags (
--host,--api-key) - Environment variables (
OCTOPRINT_HOST,OCTOPRINT_API_KEY) - Config file (
~/.octoprint-cli/config.yaml)
Config File Format
host: "http://octopi.local"
api_key: "YOUR_API_KEY_HERE"
timeout: 30
retries: 3
Agent Workflow Example
A typical autonomous print workflow:
# Step 1: Verify printer is ready
octoprint-cli preflight ./model.gcode --json
# Parse JSON, check "ready": true
# Step 2: Upload and print
octoprint-cli print ./model.gcode --confirm --json
# Parse JSON, check "status": "success"
# Step 3: Monitor progress (poll periodically)
octoprint-cli status --json
# Parse JSON, read data.job.completion and data.job.print_time_left
# Step 4: Handle completion or errors based on exit codes
# Exit 0 = success, 1 = offline, 2 = file error, 3 = busy, 4 = other
Error Handling Example
octoprint-cli status --json
echo "Exit code: $?"
{
"status": "error",
"data": null,
"error": {
"code": "CONNECTION_ERROR",
"message": "Could not connect to OctoPrint at http://octopi.local"
}
}
Exit code: 1 (printer offline)
Pre-flight Checks
The preflight command (and automatic checks before print) validates:
- Printer is connected and operational
- Printer is not already printing
- No printer errors detected
- Temperatures are within safe limits
- File exists, has valid extension, reasonable size
octoprint-cli preflight ./model.gcode --json
Temperature Control
# View current temperatures
octoprint-cli temp --json
# Set hotend to 200C and bed to 60C
octoprint-cli temp --tool 200 --bed 60 --json
# Turn off all heaters
octoprint-cli temp --off --json
Raw G-code
# Home all axes
octoprint-cli gcode G28 --json
# Multiple commands
octoprint-cli gcode G28 "M104 S200" "M140 S60" --json
Requirements
- Python 3.8+
- OctoPrint server with API access enabled
- Dependencies: click, requests, pyyaml, rich
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kiln3d_octoprint-0.2.1.tar.gz.
File metadata
- Download URL: kiln3d_octoprint-0.2.1.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18f7aab1b50d161dd687f2e3747b28d3f768041ad42c6b4385b151903e20b4af
|
|
| MD5 |
bf5bd2192bec48f60f37c24e08b702c8
|
|
| BLAKE2b-256 |
9ba04e94a2c0c14e7c8f28fa6446f4c2f84f2c03a1070494f4933d153f54424a
|
Provenance
The following attestation bundles were made for kiln3d_octoprint-0.2.1.tar.gz:
Publisher:
publish.yml on codeofaxel/Kiln
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kiln3d_octoprint-0.2.1.tar.gz -
Subject digest:
18f7aab1b50d161dd687f2e3747b28d3f768041ad42c6b4385b151903e20b4af - Sigstore transparency entry: 974602933
- Sigstore integration time:
-
Permalink:
codeofaxel/Kiln@5703ad066a9b28d9afd77ef2a793d50d9bb45e82 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/codeofaxel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5703ad066a9b28d9afd77ef2a793d50d9bb45e82 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kiln3d_octoprint-0.2.1-py3-none-any.whl.
File metadata
- Download URL: kiln3d_octoprint-0.2.1-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8daa2a3e960fe41f1d12554f3f68b8fdb89f1af0e66f4a2991917afbb9a55fb2
|
|
| MD5 |
08b438231e46987bcb38f01b1849809a
|
|
| BLAKE2b-256 |
20bc4f6c0e8750aa98ff39035c9e963fb4ac96683db38fd145893d05fab93533
|
Provenance
The following attestation bundles were made for kiln3d_octoprint-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on codeofaxel/Kiln
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kiln3d_octoprint-0.2.1-py3-none-any.whl -
Subject digest:
8daa2a3e960fe41f1d12554f3f68b8fdb89f1af0e66f4a2991917afbb9a55fb2 - Sigstore transparency entry: 974602964
- Sigstore integration time:
-
Permalink:
codeofaxel/Kiln@5703ad066a9b28d9afd77ef2a793d50d9bb45e82 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/codeofaxel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5703ad066a9b28d9afd77ef2a793d50d9bb45e82 -
Trigger Event:
release
-
Statement type: