A library to interface with the PrusaLink API
Project description
PrusaLinkPy is a library to use the Prusa Link API.
The library makes it easy to use the prusa API in python. The library is based on Request.
Example of use :
# Library import
import PrusaLinkPy
# Printer instantiation
# IP : 192.168.0.123
# API KEY : 8ojHKHGNuAHA2bM
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
# Get bed temperature
getPrint = prusaMini.get_printer()
# Display bed temperature
print(getPrint.json()["telemetry"]["temp-bed"])
# Delete a files on USB drive :
prusaMini.delete("/5H30M_~1.GCO")
# Transferring a file to the printer
if not prusaMini.exists_gcode('FOLDER/test.gcode') :
prusaMini.put_gcode('C:/AM/test.gcode', 'FOLDER/test.gcode')
# List files on USB Drive :
prusaMini.get_files().json()["children"]
# Print this file
prusaMini.post_print_gcode('/usb/test.gcode')
The library changed its name in May 2024. Before it was called prusaLink. Prusa staff asked me to leave them the name.
Change Log
2.1.0 :
- Update README.md
- added :
- delete
- get_status
- get_storage
- delete_job
2.0.1 :
- Bug correction on put_gcode
2.0.0 :
- Support firmware 5.1.0
- Added :
- get_files
- put_gcode
- exists_gcode
1.0.0 :
- First Release
Installing PrusaLinkPy and Supported Versions
PrusaLinkPy is available on pip :
python -m pip install PrusaLinkPy
PrusaLinkPy officially supports Python 3.9+ with Prusa MINI printer firmware 5.1.0.
API Reference
Low Level Functions
post_gcode(filePathLocal, remoteDir)
put_gcode(filePathLocal, remoteDir, printAfterUpload = False, overwrite = False)
post_gcode(filePathLocal, remoteDir)
High Level Functions
get_recursive_files(remoteDir)
User Guide
PrusaLinkPy.get_version()
Read version :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM", port=8017)
obj = prusaMini.get_version()
obj.json()
Return something like :
{
'api': '2.0.0',
'server': '2.1.2',
'nozzle_diameter': 0.4,
'text': 'PrusaLink',
'hostname': '',
'capabilities':
{
'upload-by-put': True
}
}
PrusaLinkPy.get_printer()
Get printer :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.get_printer()
obj.json()
Return something like :
{
'telemetry':
{
'temp-bed': 16.3,
'temp-nozzle': 16.7,
'print-speed': 100,
'z-height': 82.0,
'material': 'PLA'
},
'temperature':
{
'tool0':
{
'actual': 16.7,
'target': 0.0,
'display': 0.0,
'offset': 0
},
'bed':
{
'actual':16.3,
'target': 0.0,
'offset': 0
}
},
'state':
{
'text': 'Operational',
'flags':
{
'operational': True,
'paused': False,
'printing': False,
'cancelling': False,
'pausing': False,
'error': False,
'sdReady': False,
'closedOnError': False,
'ready': True,
'busy': False
}
}
}
PrusaLinkPy.get_job()
Get job :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.get_job()
obj.json()
Return something like :
{
"state":"Operational",
"job": None,
"progress": None
}
PrusaLinkPy.delete_job(job)
Delete a job. Job number is available with get_job() or get_status()
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.delete_job("43")
PrusaLinkPy.get_status()
Get job :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.get_status()
obj.json()
Return something like :
{
"job":
{
"id":43,
"progress":0.00,
"time_remaining":120,
"time_printing":143
},
"storage":
{
"path":"/usb/",
"name":"usb",
"read_only":false
},
"printer":
{
"state":"PRINTING",
"temp_bed":57.3,
"target_bed":0.0,
"temp_nozzle":24.1,
"target_nozzle":0.0,
"axis_z":162.2,
"flow":100,
"speed":100,
"fan_hotend":0,
"fan_print":0
}
}
PrusaLinkPy.get_storage()
Get job :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.get_storage()
obj.json()
Return something like :
TODO
PrusaLinkPy.get_files( remoteDir = '/')
Get Files on USB Drive :
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.get_files()
filesRet = obj.json()
Return something like :
{
'type': 'FOLDER',
'ro': False,
'name': 'usb',
'children':
[
{
'name': 'MTN',
'ro': False,
'type': 'FOLDER',
'm_timestamp': 1702628945,
'display_name': 'MTN'
},
{
'name': 'S2_V2IS',
'ro': False,
'type': 'FOLDER',
'm_timestamp': 1702565182,
'display_name': 'S2_V2IS'
}
]
}
Workalso with subfolder
obj = prusaMini.get_files(remoteDir = '/SUBFOLDER')
PrusaLinkPy.get_recursive_files( remoteDir = '/')
Get all files in a folder and subfolder.
Warning : return nested dict.
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
dictt = prusaMini.get_recursive_files()
{
'MTN':
{
'CHGT_BUSE.gcode': '/MTN/CHGT_B~1.GCO',
'DEBOUCHAGE.gcode': '/MTN/DEBOUC~1.GCO',
'PRECHAUFFE.gcode': '/MTN/PRECHA~1.GCO'
},
'S2_V2IS':
{
'2h33m.bgcode': '/S2_V2IS/2H33M~1.BGC',
'5h5m.bgcode': '/S2_V2IS/5H5M~1.BGC'
}
}
PrusaLinkPy.delete(remotePath)
Delete a file or a folder on USB drive
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.delete('/DEBOUC~1.GCO')
PrusaLinkPy.post_gcode(remotePath)
Print a file
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
obj = prusaMini.post_gcode('/DEBOUC~1.GCO')
PrusaLinkPy.put_gcode(remotePath, printAfterUpload = False, overwrite = False)
Send a file on USB Drive.
Can create a folder !
if ret.status_code = 409 -> Conflict : File already exists
printAfterUpload : Set at True to print after upload. Warning : Printer LCD must be on main screen !
overwrite : Allow file Overwrite
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
status = prusaMini.put('C:/MTN/DEBOUCHAGE.gcode' , 'MTN/DEBOUCHAGE.gcode')
# Overwrite
status = prusaMini.put('C:/MTN/DEBOUCHAGE.gcode' , 'MTN/DEBOUCHAGE.gcode', False, True)
# Overwrite and Print
status = prusaMini.put('C:/MTN/DEBOUCHAGE.gcode' , 'MTN/DEBOUCHAGE.gcode', True, True)
PrusaLinkPy.exists_gcode(remotePath)
Check if a file exists on USB drive.
Return True or False
import PrusaLinkPy
prusaMini = PrusaLinkPy.PrusaLinkPy("192.168.0.123", "8ojHKHGNuAHA2bM")
status = prusaMini.exists_gcode('/DEBOUC~1.GCO')
API
API not implemented in my lib :
retrieve thumbnail
r = requests.get('http://192.168.0.123:8017/thumb/l/usb/TAVERN~1.GCO', headers=headers)
/api/settings
POST /api/job Link to Buddy code
GET/POST /api/download Link to Buddy code
Bugs present in Prusa MINI printer firmware 4.4.1:
-
There is no possibility to have the list of folders present in a directory
- Solved in firmware 5
-
You cannot upload a gcode in a subfolder of the USB key
- Solved in firmware 5
-
When the printer detects the end of the filament and it displays "Change Filament" the telemetry information is no longer good. Here is the information returned by the printer in this case:
'telemetry': {'temp-bed': 0.0, 'temp-nozzle': 0.0, 'print-speed': 100, 'z-height': 0.0, 'material': '---'}
-
Still in the case of a filament change, the status information is incorrect:
'state': {'text': 'Operational', 'flags': {'operational': True, 'paused': False, 'printing': False, 'cancelling': False, 'pausing': False, 'sdReady': False, 'error': False, 'closedOnError': False, 'ready': True, 'busy': False}
Inspiration
An other lib :
https://github.com/home-assistant-libs/PrusaLinkPy/blob/main/PrusaLinkPy/
Les commandes dans la mini : https://github.com/prusa3d/Prusa-Firmware-Buddy/blob/master/lib/WUI/link_content/basic_gets.cpp
Construire la lib
py -m build
To upload to testpi repo :
py -m twine upload --repository testpi dist/*
To upload to pypi repo :
py -m twine upload dist/*
https://medium.com/analytics-vidhya/how-to-create-a-python-library-7d5aea80cc3f
Project details
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
Hashes for PrusaLinkPy-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c31fa8a3def14da92cdc388dc75196a8a9261fbfcad7092e6f91a5fa3abc3d46 |
|
MD5 | 399c4fe7b4a139bdfa72e3568bf78ae3 |
|
BLAKE2b-256 | d4e841a1ceca7c0cde330243a9536268dbe61007f151135db9bdbefcb01ffa38 |