AmiSMB / OctoRest

Python client library for OctoPrint REST API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 key
      • Verifying a temporary session key
  • Connection handling
    • Get connection settings
    • Issue a connection command
      • Connect
      • Disconnect
      • Fake_ack
  • File operations
    • Retrieve all files
    • Retrieve files from specific location
    • Upload file or create folder
    • Retrieve a specific file’s or folder’s information
    • Issue a file command
      • Select
      • Slice (TODO: profile.* and position)
      • Copy
      • Move
    • Delete file
  • Job operations
    • Issue a job command
      • Start
      • Cancel
      • Restart
      • Pause
        • Pause
        • Resume
        • Toggle
    • Retrieve information about the current job
  • Languages
    • Retrieve installed language packs
    • Upload a language pack
    • Delete a language pack
  • Log file management
  • Printer operations
    • Retrieve the current printer state
    • Issue a print head command
      • Jog
      • Home
      • Feedrate
    • Issue a tool command
      • Target
      • Offset
      • Select
      • Extrude
      • Flowrate
    • Retrieve the current tool state
    • Issue a bed command
      • Target
      • Offset
    • Retrieve the current bed state
    • Issue an SD command
      • Init
      • Refresh
      • Release
    • Retrieve the current SD state
    • Send 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 settings
    • Save settings
    • Regenerate the system wide API key
  • Slicing
    • List All Slicers and Slicing Profiles
    • List Slicing Profiles of a Specific Slicer
    • Retrieve Specific Profile
    • Add Slicing Profile
    • Delete Slicing Profile
  • System
    • List all registered system commands
    • List all registered system commands for a source
    • Execute a registered system command
  • Timelapse
    • Retrieve a list of timelapses and the current config
    • Delete a timelapse
    • Issue a command for an unrendered timelapse
      • Render
    • Delete an unrendered timelapse
    • Change current timelapse config
  • User
    • Retrieve a list of users
    • Retrieve a user
    • Add a user
    • Update a user
    • Delete a user
    • Reset a user’s password
    • Retrieve a user’s settings
    • Update a user’s settings
    • Regenerate a user’s personal API key
    • Delete a user’s personal API key
  • Util
    • Test paths or URLs
      • Path
      • URL
      • Server
  • Wizard
    • Retrieve additional data about registered wizards
    • Finish 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.

About

Python client library for OctoPrint REST API

License:Other


Languages

Language:Python 100.0%