Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
timezone: "Europe/Berlin"
day: "monday"
time: "05:00"
groups:
gh-dependencies:
patterns:
- "*"
- package-ecosystem: "pip"
directory: "/" #
schedule:
interval: "monthly"
timezone: "Europe/Berlin"
day: "monday"
time: "05:00"
groups:
pip-dependencies:
patterns:
- "*"
38 changes: 38 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: python test

on:
push:
pull_request:
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab

jobs:
typing:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [
'3.11',
'3.12',
'3.13',
]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Install dependencies.
run: |
pip install .
# pip install .[type]

- name: Run test.
run: |
python -m unittest
# mypy .\ultimaker\

- name: Run lint checks.
uses: pre-commit/[email protected]
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ venv.bak/
.mypy_cache/

# Visual Studio Code
.vscode
.vscode
.idea/
55 changes: 55 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-illegal-windows-names
- id: check-json
- id: check-toml
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: forbid-submodules
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-no-eval
- id: python-use-type-annotations
- id: text-unicode-replacement-char

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.5.1
hooks:
- id: pyproject-fmt

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.8
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format

- repo: https://github.com/rhysd/actionlint
rev: v1.7.7
hooks:
- id: actionlint

- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
- tomli
exclude: "doc/(api|api-cluster).json"
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

114 changes: 20 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,34 @@
# python-ultimaker-printer-api

An Ultimaker Printer API Client implementation in Python derived from Swagger documentation (see http://printer_ip/docs/api/) and request testing.
An Ultimaker Printer API Client implementation in Python.
Derived from Swagger documentation (see http://printer_ip/docs/api/) and request testing.

[![Build Status](https://travis-ci.org/vanderbilt-design-studio/python-ultimaker-printer-api.svg?branch=master)](https://travis-ci.org/vanderbilt-design-studio/python-ultimaker-printer-api)
## Support

[![Coverage Status](https://coveralls.io/repos/github/vanderbilt-design-studio/python-ultimaker-printer-api/badge.svg?branch=master)](https://coveralls.io/github/vanderbilt-design-studio/python-ultimaker-printer-api?branch=master)
| Printer | Support | Tested | Notes |
|-----------|---------|--------|-------|
| UM 2+ Con | 🏁 | ❓ | |
| UM S3 | ✔️ | ❓ | |
| UM S3 | ✔️ | ❓ | |

## Demo

See https://github.com/vanderbilt-design-studio/poller-pi/blob/master/printers.py. This powers printer feed retrieval for https://vanderbilt.design/ (scroll down to the bottom)

## Usage
```python
from ultimaker import Printer, Identity, CredentialsDict
IDENTITY = Identity('Application', 'Anonymous')
IP = '192.168.1.18'
PORT = 80

credentials_dict = CredentialsDict('credentials.json')

printer = Printer(IP, PORT, IDENTITY)
printer.put_system_display_message("It's over, Anakin!", "Acquire high ground")

```

## mDNS
[No local printing](https://support.makerbot.com/s/article/1667412440858)

If your local network supports mDNS (some school/corproate networks disable it), printers can be automatically discovered with the zeroconf package.
## API Documentation

```python
ultimaker_application_name = 'Application'
ultimaker_user_name = 'Anonymous
ultimaker_credentials_filename = './credentials.shelve'
* http://[printer_ip_here]/cluster-api/v1/ for printer and print job management.
* http://[printer_ip_here]/docs/api for low-level access to the printer's parameters and system.

Source: https://support.makerbot.com/s/article/1667412427787

from typing import Dict, List
import logging
import json
import socket
import base64
import uuid
import shelve

from zeroconf import ServiceInfo
from ultimaker import Printer, Credentials, Identity
import imagehash

class PrinterListener:

def __init__(self, credentials_dict: shelve.Shelf):
self.printers_by_name: Dict[str, Printer] = {}
self.credentials_dict: shelve.Shelf = credentials_dict

def remove_service(self, zeroconf, type, name):
del self.printers_by_name[name]
logging.info(f"Service {name} removed")

def add_service(self, zeroconf, type, name):
info: ServiceInfo = zeroconf.get_service_info(type, name)
if len(info.addresses) == 0:
logging.warning(f"Service {name} added but had no IP address, cannot add")
return
address = socket.inet_ntoa(info.addresses[0])
identity = Identity(ultimaker_application_name, ultimaker_user_name)
credentials = self.credentials_dict.get(str(printer.get_system_guid()), None)
self.printers_by_name[name] = Printer(address, info.port, identity,
credentials)
logging.info(f"Service {name} added with guid: {printer.get_system_guid()}")
## Demo

def printer_jsons(self) -> List[Dict[str, str]]:
printer_jsons: List[Dict[str, str]] = []
# Convert to list here to prevent concurrent changes by zeroconf affecting the loop
for printer in list(self.printers_by_name.values()):
try:
printer_status_json: Dict[str, str] = printer.into_ultimaker_json()
printer_jsons.append(printer_status_json)
See https://github.com/vanderbilt-design-studio/poller-pi/blob/master/printers.py.
This powers printer feed retrieval for https://vanderbilt.design/ (scroll down to the bottom).

if printer.credentials is not None and str(printer.get_system_guid(
)) not in self.credentials_dict:
logging.info(
f'Did not see credentials for {printer.get_system_guid()} in credentials, adding and saving'
)
self.credentials_dict[str(printer.get_system_guid())] = printer.credentials
self.credentials_dict.sync()
except Exception as e:
if type(e) is KeyboardInterrupt:
raise e
logging.warning(
f'Exception getting info for printer {printer.get_system_guid()}, it may no longer exist: {e}'
)
return printer_jsons
## Usage

See folder `scripts`.

if __name__ == '__main__':
from zeroconf import ServiceBrowser, Zeroconf
zeroconf = Zeroconf()
shelf = shelve.open(ultimaker_credentials_filename)
listener = PrinterListener(shelf)
browser = ServiceBrowser(zeroconf, "_ultimaker._tcp.local.", listener)
try:
input('Press enter to exit\n')
finally:
print('Exiting...')
shelf.close()
zeroconf.close()
## mDNS

```
If your local network supports mDNS (some school/corporate networks disable it), printers can be automatically discovered with the zeroconf package. Use script `mdns.py`.
3 changes: 3 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Documentation

This folder contains the reference documentation from the Ultimaker printer.
Loading