A Go client library for interacting with 3D printing services, including OctoPrint and Spoolman.
- OctoPrint Client: Full API client for OctoPrint with printer control, job monitoring, and temperature management
- Spoolman Client: API client for Spoolman filament tracking
- Configuration Management: Shared configuration loader for multi-printer setups
- Type-Safe Models: Comprehensive data models for all API responses
go get github.com/wmarchesi123/go-3dprint-clientThe library expects environment variables for configuration:
# Spoolman API URL
SPOOLMAN_URL=http://spoolman:7912
# Printer 1 Configuration
PRINTER_1_NAME=Purple-MK4S
PRINTER_1_URL=http://purple-octoprint
PRINTER_1_KEY=your-api-key-here
# Printer 2 Configuration
PRINTER_2_NAME=Original-MK4S
PRINTER_2_URL=http://original-octoprint
PRINTER_2_KEY=your-api-key-hereimport "github.com/wmarchesi123/go-3dprint-client/config"
cfg, err := config.LoadConfig()
if err != nil {
log.Fatal(err)
}import "github.com/wmarchesi123/go-3dprint-client/octoprint"
// Create a client
client := octoprint.NewClient("http://octoprint-url", "api-key")
// Get printer state
state, err := client.GetPrinterState()
if err != nil {
log.Fatal(err)
}
// Get current job
job, err := client.GetJob()
if err != nil {
log.Fatal(err)
}
// Set temperatures
err = client.SetToolTemperature(0, 215.0) // Tool 0 to 215°C
err = client.SetBedTemperature(60.0) // Bed to 60°C
// Get current spool
spoolID, err := client.GetCurrentSpool(0) // Tool 0
// Set active spool
err = client.SetActiveSpool("123", 0) // Spool ID 123 on tool 0
// Get thumbnail URL
thumbnailURL := client.GetThumbnail("/path/to/file.gcode")import "github.com/wmarchesi123/go-3dprint-client/spoolman"
// Create a client
client := spoolman.NewClient("http://spoolman-url")
// Get a specific spool
spool, err := client.GetSpool("123")
if err != nil {
log.Fatal(err)
}
// Get all spools
spools, err := client.GetAllSpools()
if err != nil {
log.Fatal(err)
}
// Format spool info for display
info := spoolman.FormatSpoolInfo(spool)
fmt.Printf("Spool: %s, Material: %s, Remaining: %.1fg\n",
info["name"], info["material"], info["remaining"])GetPrinterState()- Get printer state and temperaturesGetJob()- Get current print job informationGetCurrentSpool(tool)- Get the currently selected spool IDSetActiveSpool(spoolID, tool)- Set the active spool for a toolGetThumbnail(path)- Get the thumbnail URL for a G-code fileSetToolTemperature(tool, target)- Set hotend temperatureSetBedTemperature(target)- Set bed temperature
GetSpool(id)- Get a specific spool by IDGetAllSpools()- Get all spoolsFormatSpoolInfo(spool)- Format spool data for display
LoadConfig()- Load configuration from environment variables