OctoRest
Python client library for OctoPrint REST API
This is continued work after the great start by Miro Hrončok of covering the OctoPrint REST API. Nearly all current functionality in the API has been covered, but as of yet I have not had time to add extensive testing. (Will do...)
Installation
The easiest way to install the package is via pip
:
$ pip install octorest
Examples
You may want a function which returns an instance of the OctoRest object connected to your printer.
def make_client(url, apikey):
"""Creates and returns an instance of the OctoRest client.
Args:
url - the url to the OctoPrint server
apikey - the apikey from the OctoPrint server found in settings
"""
try:
client = OctoRest(url=url, apikey=apikey)
return client
except ConnectionError as ex:
# Handle exception as you wish
print(ex)
Once we have a client we can do many a cool thing with it! For example the following retrieves all the G-code file names on your OctoPrint server and adds them to a string which is printed out.
def file_names(client):
"""Retrieves the G-code file names from the
OctoPrint server and returns a string message listing the
file names.
Args:
client - the OctoRest client
"""
message = "The GCODE files currently on the printer are:\n\n"
for k in client.files()['files']:
message += k['name'] + "\n"
print(message)
Maybe you want to stop your print and then subsequently home the printer. This is very simple to do using OctoRest!
def toggle_home(client):
"""Toggles the current print (if printing it pauses and
if paused it starts printing) and then homes all of
the printers axes.
Args:
client - the OctoRest client
"""
print("Toggling the print!")
client.pause()
print("Homing your 3d printer...")
client.home()
Implemented features of OctoPrint REST API
A check list of the features currently implemented can be seen below.
Version information- Apps
- Session Keys
Obtaining a temporary session keyVerifying a temporary session key
- Connection handling
Get connection settingsIssue a connection commandConnectDisconnectFake_ack
- File operations
Retrieve all filesRetrieve files from specific locationUpload file or create folderRetrieve a specific file’s or folder’s information- Issue a file command
Select- Slice (TODO: profile.* and position)
CopyMove
Delete file
- Job operations
- Issue a job command
StartCancelRestart- Pause
- Pause
- Resume
Toggle
Retrieve information about the current job
- Languages
Retrieve installed language packsUpload a language packDelete a language pack
- Log file management
- Printer operations
Retrieve the current printer stateIssue a print head commandJogHomeFeedrate
Issue a tool commandTargetOffsetSelectExtrudeFlowrate
Retrieve the current tool stateIssue a bed commandTargetOffset
Retrieve the current bed stateIssue an SD commandInitRefreshRelease
Retrieve the current SD stateSend an arbitrary command to the printer
- Printer profile operations
Retrieve all printer profiles- Add a new printer profile
- Update an existing printer profile
Remove an existing printer profile
- Settings
Retrieve current settingsSave settings- Regenerate the system wide API key
- Slicing
List All Slicers and Slicing ProfilesList Slicing Profiles of a Specific SlicerRetrieve Specific Profile- Add Slicing Profile
Delete Slicing Profile
- System
List all registered system commandsList all registered system commands for a sourceExecute a registered system command
- Timelapse
Retrieve a list of timelapses and the current configDelete a timelapseIssue a command for an unrendered timelapseRender
Delete an unrendered timelapseChange current timelapse config
- User
Retrieve a list of usersRetrieve a userAdd a userUpdate a userDelete a userReset a user’s passwordRetrieve a user’s settings- Update a user’s settings
Regenerate a user’s personal API keyDelete a user’s personal API key
- Util
- Test paths or URLs
- Path
- URL
- Server
- Wizard
Retrieve additional data about registered wizardsFinish wizards
Copyright & License
Copyright (c) 2016-2017 Miro Hrončok. MIT License.
Copyright (c) 2017 Jiří Makarius. MIT License.
Copyright (c) 2018, Douglas Brion. MIT License.