Skip to main content

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 (up to OctoPrint 1.3.11), but as of yet I have not had time to add extensive testing for all aspects of the API.

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.toggle()
     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.

  • General information
    • [ ] Authorization

    • [ ] Login

    • [ ] Logout

  • Version information
    • [X] Version information

  • Apps
    • [ ] Session Keys (Deprecated since version 1.3.11: This functionality will be removed in 1.4.0. Use the Application Keys Plugin workflow instead.)

      • [ ] Obtaining a temporary session key

      • [ ] Verifying a temporary session key

    • [ ] Application Keys Plugin workflow

      • [X] Probe workflow support

      • [X] Start authorization process

      • [X] Poll for decision on existing request

      • [ ] Decide on existing request

      • [ ] Fetch list of existing application keys

      • [ ] Issue an application key command

  • Connection handling
    • [X] Get connection settings

    • [X] Issue a connection command

      • [X] Connect

      • [X] Disconnect

      • [X] Fake_ack

  • File operations
    • [X] Retrieve all files

    • [X] Retrieve files from specific location

    • [X] Upload file or create folder

    • [X] Retrieve a specific file’s or folder’s information

    • [X] Issue a file command

      • [X] Select

      • [X] Slice

      • [X] Copy

      • [X] Move

    • [X] Delete file

  • Job operations
    • [X] Issue a job command

      • [X] Start

      • [X] Cancel

      • [X] Restart

      • [X] Pause

        • [X] Pause

        • [X] Resume

        • [X] Toggle

    • [X] Retrieve information about the current job

  • Languages
    • [X] Retrieve installed language packs

    • [X] Upload a language pack

    • [X] Delete a language pack

  • Log file management
    • [X] Retrieve a list of available log files

    • [X] Delete a specific logfile

  • Printer operations
    • [X] Retrieve the current printer state

    • [X] Issue a print head command

      • [X] Jog

      • [X] Home

      • [X] Feedrate

    • [X] Issue a tool command

      • [X] Target

      • [X] Offset

      • [X] Select

      • [X] Extrude

      • [X] Flowrate

    • [X] Retrieve the current tool state

    • [X] Issue a bed command

      • [X] Target

      • [X] Offset

    • [X] Retrieve the current bed state

    • [X] Issue a chamber command

      • [X] Target

      • [X] Offset

    • [X] Retrieve the current chamber state

    • [X] Issue an SD command

      • [X] Init

      • [X] Refresh

      • [X] Release

    • [X] Retrieve the current SD state

    • [X] Retrieve custom controls from config.yaml

    • [X] Send an arbitrary command to the printer

  • Printer profile operations
    • [X] Retrieve all printer profiles

    • [X] Retrieve specific printer profile

    • [ ] Add a new printer profile

    • [ ] Update an existing printer profile

    • [X] Remove an existing printer profile

  • Settings
    • [X] Retrieve current settings

    • [X] Save settings

    • [ ] Regenerate the system wide API key

    • [ ] Fetch template data (in beta)

  • Slicing
    • [X] List All Slicers and Slicing Profiles

    • [X] List Slicing Profiles of a Specific Slicer

    • [X] Retrieve Specific Profile

    • [ ] Add Slicing Profile

    • [X] Delete Slicing Profile

  • System
    • [X] List all registered system commands

    • [X] List all registered system commands for a source

    • [X] Execute a registered system command

  • Timelapse
    • [X] Retrieve a list of timelapses and the current config

    • [X] Delete a timelapse

    • [X] Issue a command for an unrendered timelapse

      • [X] Render

    • [X] Delete an unrendered timelapse

    • [X] Change current timelapse config

  • User
    • [X] Retrieve a list of users

    • [X] Retrieve a user

    • [X] Add a user

    • [X] Update a user

    • [X] Delete a user

    • [X] Reset a user’s password

    • [X] Retrieve a user’s settings

    • [ ] Update a user’s settings

    • [X] Regenerate a user’s personal API key

    • [X] Delete a user’s personal API key

  • Util
    • [X] Test paths or URLs

      • [X] Path

      • [X] URL

      • [X] Server

  • Wizard
    • [X] Retrieve additional data about registered wizards

    • [X] Finish wizards

Metadata

Release files for octorest 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for octorest 0.4
File Size Uploaded
octorest-0.4.tar.gz 74.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for octorest 0.4
File Interpreter ABI Platform
octorest-0.4-py3-none-any.whl Python 3 none any Details

Total release size: 95.5 kB

Release files / octorest-0.4.tar.gz

Download URL octorest-0.4.tar.gz
Size 74.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6ce49bddfcd36ba0073556ef940f786edc69394e8779bc960d31969c60661a3b
BLAKE2b-256 checksum
How to use checksums
68a28b0dcee10e90ccdf3f29ce9e06c33862401f4a429daf59b85e5e3283377c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1

Release files / octorest-0.4-py3-none-any.whl

Download URL octorest-0.4-py3-none-any.whl
Size 21.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e70512cb0aaf3f576c4736e97e372e1497c0a97bfec64c0466826c6c27588d6
BLAKE2b-256 checksum
How to use checksums
a45790604d13ebf28f646c58697f204b9bf0816bbef5644878b8586ad4267220
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page