Python
The official Python library for the Superslice API.
Python 3.10 or newer. The only dependency is httpx.
Source, issues and releases: superslice-co/superslice-python.
Install
The package is not yet published to PyPI. Until it is, install from GitHub:
pip install "git+https://github.com/superslice-co/superslice-python.git"Quickstart
from superslice import Superslice
client = Superslice() # reads SUPERSLICE_API_KEY, or pass api_key="sk_..."
slice = client.slices.create(
{
"slicer": "bambu-studio",
"printer": "Bambu Lab A1 0.4 nozzle",
"process": "0.20mm Standard @BBL A1",
"filament": "Bambu PLA Basic @BBL A1",
},
file="cube.stl", # a path, bytes, or a binary file object
)
slice = client.slices.wait(slice["id"]) # polls until succeeded or failed
if slice["status"] == "succeeded":
result = slice["result"]
print(result["print_time_s"], "s")
print(result["filament_g"], "g")
if slice["price"]:
print(slice["price"]["total_minor"], slice["price"]["currency"]) # integer minor units
else:
print("failed:", slice["error"]["code"])To slice a model you already uploaded or a public URL, leave out file and pass "model": {"id": "mdl_..."} or "model": {"source_url": "https://..."} in the params.
AsyncSuperslice has the same methods as coroutines:
import asyncio
from superslice import AsyncSuperslice
async def main():
async with AsyncSuperslice() as client:
s = await client.slices.create(params, file="cube.stl")
s = await client.slices.wait(s["id"])
async for item in client.slices.list_all():
print(item["id"])
asyncio.run(main())Responses are plain dicts. superslice.types has a TypedDict for every shape, so type checkers know the fields. Fields the API adds later stay in the dict.
Catalogue lookup
engines = client.engines.list()["data"]
release = next(e["id"] for e in engines if e["slicer"] == "bambu-studio" and e["status"] == "active")
printers = client.engines.printers(release)["data"]
name = printers[0]["name"]
client.engines.processes(release, name)
client.engines.filaments(release, name)
client.engines.plate_types(release, name)Releases contain @ and +. The library percent-encodes them for you.
Idempotency
Pass a key and a repeated call returns the same slice instead of slicing again:
client.slices.create(params, file="cube.stl", idempotency_key="order-1042")The same key with a different body raises ConflictError with code idempotency_conflict.
Errors
Every error extends SupersliceError and carries status, code, title, errors, retry_after and the raw body.
| Class | When |
|---|---|
AuthenticationError | 401 |
PermissionError | 403 |
NotFoundError | 404 |
ConflictError | 409 |
RateLimitError | 429 |
InvalidRequestError | 400, 413 |
PlanLimitError | 402 |
ServerError | 5xx |
APIConnectionError | no response |
APITimeoutError | request timeout, or slices.wait ran out of time |
from superslice import InvalidRequestError, NotFoundError
try:
client.slices.get("slc_missing")
except NotFoundError as e:
print(e.status, e.code)
except InvalidRequestError as e:
print(e.errors) # [{"path": ..., "message": ...}]PermissionError shadows the builtin of the same name inside any module that imports it from superslice. Use superslice.PermissionError if that matters.
A slice that fails is not an exception. slices.wait returns it with status == "failed" and error set.
Retries
On 429 the library waits Retry-After seconds (1 s if the header is missing). On 5xx and network errors it backs off 0.5 s, 1 s, 2 s. The default is 2 retries.
POST /v1/slices is retried only when you pass an idempotency_key, because a blind retry could slice twice. POST /v1/presets is never retried. GET, PUT, PATCH and DELETE retry freely.
Webhooks
Verify the Superslice-Signature header against the raw request body, before parsing JSON:
from superslice import Webhooks, SignatureVerificationError
try:
event = Webhooks.verify(secret, request.headers["Superslice-Signature"], raw_body)
except SignatureVerificationError:
return 400
if event["event"] == "slice.completed":
print(event["data"]["result"]["print_time_s"])client.webhooks.verify(...) is the same function. It accepts a signature if any v1 value matches and rejects timestamps more than 300 seconds old (tolerance_seconds= changes that). Events can arrive more than once; store event_id.
Configuration
Superslice(
api_key="sk_...", # default: SUPERSLICE_API_KEY
base_url="https://api.superslice.co", # default
timeout=60.0, # seconds
max_retries=2,
)Pass http_client=httpx.Client(...) to bring your own transport or proxy settings. Use the client as a context manager (with / async with) or call close() / await aclose().
Other resources: client.models, client.presets, client.pricing, client.slicers.