Skip to main content

FastAPI router and job engine for streaming G-code to GRBL controllers

Project description

pygrbl-server

FastAPI router and thread-safe job engine for streaming G-code to GRBL controllers. A library, not an application: mount the router in your own FastAPI app and run it with the ASGI server of your choice. One active job per serial port, live status, and a retained terminal result per port.

Part of the pygrbl family: pygrbl-build (generate G-code) → pygrbl-streamer (stream to GRBL) → pygrbl-server (expose over HTTP).

Install

pip install pygrbl-server

Dependencies: fastapi and pygrbl-streamer. Bring your own ASGI server.

Usage

from contextlib import asynccontextmanager

from fastapi import FastAPI
from pygrbl_server import JobRegistry, create_router

registry = JobRegistry()  # streamer_factory(port, baudrate), defaults to GrblStreamer


@asynccontextmanager
async def lifespan(app: FastAPI):
    yield
    registry.shutdown()


app = FastAPI(lifespan=lifespan)
app.include_router(create_router(registry))
uvicorn yourmodule:app --host 0.0.0.0 --port 8000

Events are logged to the pygrbl_server logger (alarms and failures at WARNING/ERROR). Inject a custom streamer_factory to swap the streamer backend.

API

Endpoint Description
POST /stream Start a job: {"port": "...", "files": [...]}. 202 started, 409 port busy, 404 file missing.
POST /stop?port= Cancel the active job. 404 if none.
POST /pause?port=&paused= Feed hold (true, default) or resume (false). 404 if none.
GET /status?port= Port state; omit port for all ports.

Status is idle, working, paused, or the retained done / error of the last finished job (kept until a new job starts on that port):

curl 'localhost:8000/status?port=/dev/ttyUSB0'
# {"port": "/dev/ttyUSB0", "status": "working", "progress": 42, "error": null}

Security

No authentication. Any client that can reach the port can control physical machines capable of causing fires or injury. Run on a trusted LAN only. The files in /stream are paths on the server's filesystem, not uploads. Auth, TLS, and rate limiting belong in the app that mounts the router.

Design

The library streams files and reports state; everything else lives in your layers:

  • Machine setup (homing, air assist, preambles) belongs in your G-code.
  • Delays between files: M5 + G4 P<seconds> in your G-code.
  • Notifications: poll /status or attach a handler to the pygrbl_server logger.
  • Runner, CLI, auth, CORS: your app's job — this ships as a router on purpose.

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

pygrbl_server-0.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygrbl_server-0.0.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file pygrbl_server-0.0.1.tar.gz.

File metadata

  • Download URL: pygrbl_server-0.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygrbl_server-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3555d6bcd4720176f246d9bf15e46ac0dbaa4f154ac36aacc9b8d1c0bc7f2bbd
MD5 0900b47c638110f2a91534eb060cc35f
BLAKE2b-256 4e9ad4cb36fbe208eb575f5dabdcad4e8958ebe9c02c77ec1dc9d933b219503a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygrbl_server-0.0.1.tar.gz:

Publisher: publish.yml on offerrall/pygrbl-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygrbl_server-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pygrbl_server-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pygrbl_server-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bf97f3ae9ef4930141f768bb8b8f599988a98fc468e6c4cd4bfaeb0754deb417
MD5 866db78d803377654e13494d7adb090b
BLAKE2b-256 12f4b2ae82ab3fbb393f648008dcb6abc22fcb2fa40d4beb52224f88316962bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygrbl_server-0.0.1-py3-none-any.whl:

Publisher: publish.yml on offerrall/pygrbl-server

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page