superslice 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,19 @@
1
+ name: ci
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+ jobs:
7
+ test:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ python: ["3.10", "3.11", "3.12", "3.13"]
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: ${{ matrix.python }}
17
+ - run: pip install -e ".[dev]"
18
+ - run: mypy
19
+ - run: pytest
@@ -0,0 +1,22 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ tags: ['v*']
5
+ permissions:
6
+ contents: read
7
+ id-token: write # PyPI Trusted Publishing (OIDC), no token stored
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: actions/setup-python@v5
14
+ with:
15
+ python-version: '3.13'
16
+ - name: Tag matches pyproject version
17
+ run: test "${GITHUB_REF_NAME#v}" = "$(python -c 'import tomllib;print(tomllib.load(open("pyproject.toml","rb"))["project"]["version"])')"
18
+ - run: pip install -e ".[dev]" build
19
+ - run: mypy
20
+ - run: pytest
21
+ - run: python -m build
22
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ .mypy_cache/
6
+ .pytest_cache/
7
+ local-key.txt
8
+ .env
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Superslice
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,206 @@
1
+ Metadata-Version: 2.5
2
+ Name: superslice
3
+ Version: 0.1.0
4
+ Summary: Official Python library for the Superslice API
5
+ Project-URL: Homepage, https://docs.superslice.co
6
+ Project-URL: Repository, https://github.com/superslice-co/superslice-python
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: 3d-printing,api-client,sdk,slicer,superslice
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Typing :: Typed
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: httpx<1,>=0.24
18
+ Provides-Extra: dev
19
+ Requires-Dist: mypy; extra == 'dev'
20
+ Requires-Dist: pytest; extra == 'dev'
21
+ Requires-Dist: pytest-asyncio; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ <p align="center">
25
+ <a href="https://superslice.co"><img src=".github/banner.png" alt="Superslice for Python" width="100%"></a>
26
+ </p>
27
+
28
+ <p align="center">
29
+ <a href="https://github.com/superslice-co/superslice-python/actions/workflows/ci.yml"><img src="https://github.com/superslice-co/superslice-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
30
+ <img src="https://img.shields.io/badge/Python-3.10%2B-121314" alt="Python 3.10+">
31
+ <img src="https://img.shields.io/badge/licence-MIT-97d9c2" alt="MIT licence">
32
+ </p>
33
+
34
+ <p align="center">
35
+ <a href="https://docs.superslice.co">Docs</a> ·
36
+ <a href="https://docs.superslice.co/api/post-slices">API reference</a> ·
37
+ <a href="https://app.superslice.co/keys">Get an API key</a> ·
38
+ <a href="https://status.superslice.co">Status</a>
39
+ </p>
40
+
41
+ # Superslice for Python
42
+
43
+ Superslice is a slicing API for 3D print quotes: send a model and get print time, filament use and a price from the real Bambu Studio, PrusaSlicer, Creality Print or ElegooSlicer engine.
44
+
45
+ Python 3.10 or newer. The only dependency is `httpx`.
46
+
47
+ ## Install
48
+
49
+ The package is not yet published to PyPI. Until it is, install from GitHub:
50
+
51
+ ```sh
52
+ pip install "git+https://github.com/superslice-co/superslice-python.git"
53
+ ```
54
+
55
+ ## Quickstart
56
+
57
+ ```python
58
+ from superslice import Superslice
59
+
60
+ client = Superslice() # reads SUPERSLICE_API_KEY, or pass api_key="sk_..."
61
+
62
+ slice = client.slices.create(
63
+ {
64
+ "slicer": "bambu-studio",
65
+ "printer": "Bambu Lab A1 0.4 nozzle",
66
+ "process": "0.20mm Standard @BBL A1",
67
+ "filament": "Bambu PLA Basic @BBL A1",
68
+ },
69
+ file="cube.stl", # a path, bytes, or a binary file object
70
+ )
71
+
72
+ slice = client.slices.wait(slice["id"]) # polls until succeeded or failed
73
+
74
+ if slice["status"] == "succeeded":
75
+ result = slice["result"]
76
+ print(result["print_time_s"], "s")
77
+ print(result["filament_g"], "g")
78
+ if slice["price"]:
79
+ print(slice["price"]["total_minor"], slice["price"]["currency"]) # integer minor units
80
+ else:
81
+ print("failed:", slice["error"]["code"])
82
+ ```
83
+
84
+ 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.
85
+
86
+ `AsyncSuperslice` has the same methods as coroutines:
87
+
88
+ ```python
89
+ import asyncio
90
+ from superslice import AsyncSuperslice
91
+
92
+ async def main():
93
+ async with AsyncSuperslice() as client:
94
+ s = await client.slices.create(params, file="cube.stl")
95
+ s = await client.slices.wait(s["id"])
96
+ async for item in client.slices.list_all():
97
+ print(item["id"])
98
+
99
+ asyncio.run(main())
100
+ ```
101
+
102
+ 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.
103
+
104
+ ## Catalogue lookup
105
+
106
+ ```python
107
+ engines = client.engines.list()["data"]
108
+ release = next(e["id"] for e in engines if e["slicer"] == "bambu-studio" and e["status"] == "active")
109
+
110
+ printers = client.engines.printers(release)["data"]
111
+ name = printers[0]["name"]
112
+ client.engines.processes(release, name)
113
+ client.engines.filaments(release, name)
114
+ client.engines.plate_types(release, name)
115
+ ```
116
+
117
+ Releases contain `@` and `+`. The library percent-encodes them for you.
118
+
119
+ ## Idempotency
120
+
121
+ Pass a key and a repeated call returns the same slice instead of slicing again:
122
+
123
+ ```python
124
+ client.slices.create(params, file="cube.stl", idempotency_key="order-1042")
125
+ ```
126
+
127
+ The same key with a different body raises `ConflictError` with code `idempotency_conflict`.
128
+
129
+ ## Errors
130
+
131
+ Every error extends `SupersliceError` and carries `status`, `code`, `title`, `errors`, `retry_after` and the raw `body`.
132
+
133
+ | Class | When |
134
+ |---|---|
135
+ | `AuthenticationError` | 401 |
136
+ | `PermissionError` | 403 |
137
+ | `NotFoundError` | 404 |
138
+ | `ConflictError` | 409 |
139
+ | `RateLimitError` | 429 |
140
+ | `InvalidRequestError` | 400, 413 |
141
+ | `PlanLimitError` | 402 |
142
+ | `ServerError` | 5xx |
143
+ | `APIConnectionError` | no response |
144
+ | `APITimeoutError` | request timeout, or `slices.wait` ran out of time |
145
+
146
+ ```python
147
+ from superslice import InvalidRequestError, NotFoundError
148
+
149
+ try:
150
+ client.slices.get("slc_missing")
151
+ except NotFoundError as e:
152
+ print(e.status, e.code)
153
+ except InvalidRequestError as e:
154
+ print(e.errors) # [{"path": ..., "message": ...}]
155
+ ```
156
+
157
+ `PermissionError` shadows the builtin of the same name inside any module that imports it from `superslice`. Use `superslice.PermissionError` if that matters.
158
+
159
+ A slice that fails is not an exception. `slices.wait` returns it with `status == "failed"` and `error` set.
160
+
161
+ ## Retries
162
+
163
+ 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.
164
+
165
+ `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.
166
+
167
+ ## Webhooks
168
+
169
+ Verify the `Superslice-Signature` header against the raw request body, before parsing JSON:
170
+
171
+ ```python
172
+ from superslice import Webhooks, SignatureVerificationError
173
+
174
+ try:
175
+ event = Webhooks.verify(secret, request.headers["Superslice-Signature"], raw_body)
176
+ except SignatureVerificationError:
177
+ return 400
178
+ if event["event"] == "slice.completed":
179
+ print(event["data"]["result"]["print_time_s"])
180
+ ```
181
+
182
+ `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`.
183
+
184
+ ## Configuration
185
+
186
+ ```python
187
+ Superslice(
188
+ api_key="sk_...", # default: SUPERSLICE_API_KEY
189
+ base_url="https://api.superslice.co", # default
190
+ timeout=60.0, # seconds
191
+ max_retries=2,
192
+ )
193
+ ```
194
+
195
+ 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()`.
196
+
197
+ Other resources: `client.models`, `client.presets`, `client.pricing`, `client.slicers`.
198
+
199
+ ## Links
200
+
201
+ - Docs: https://docs.superslice.co
202
+ - API reference: https://docs.superslice.co/api/post-slices
203
+ - Status: https://status.superslice.co
204
+ - Support: hello@superslice.co
205
+
206
+ MIT licence.
@@ -0,0 +1,183 @@
1
+ <p align="center">
2
+ <a href="https://superslice.co"><img src=".github/banner.png" alt="Superslice for Python" width="100%"></a>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://github.com/superslice-co/superslice-python/actions/workflows/ci.yml"><img src="https://github.com/superslice-co/superslice-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
7
+ <img src="https://img.shields.io/badge/Python-3.10%2B-121314" alt="Python 3.10+">
8
+ <img src="https://img.shields.io/badge/licence-MIT-97d9c2" alt="MIT licence">
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://docs.superslice.co">Docs</a> ·
13
+ <a href="https://docs.superslice.co/api/post-slices">API reference</a> ·
14
+ <a href="https://app.superslice.co/keys">Get an API key</a> ·
15
+ <a href="https://status.superslice.co">Status</a>
16
+ </p>
17
+
18
+ # Superslice for Python
19
+
20
+ Superslice is a slicing API for 3D print quotes: send a model and get print time, filament use and a price from the real Bambu Studio, PrusaSlicer, Creality Print or ElegooSlicer engine.
21
+
22
+ Python 3.10 or newer. The only dependency is `httpx`.
23
+
24
+ ## Install
25
+
26
+ The package is not yet published to PyPI. Until it is, install from GitHub:
27
+
28
+ ```sh
29
+ pip install "git+https://github.com/superslice-co/superslice-python.git"
30
+ ```
31
+
32
+ ## Quickstart
33
+
34
+ ```python
35
+ from superslice import Superslice
36
+
37
+ client = Superslice() # reads SUPERSLICE_API_KEY, or pass api_key="sk_..."
38
+
39
+ slice = client.slices.create(
40
+ {
41
+ "slicer": "bambu-studio",
42
+ "printer": "Bambu Lab A1 0.4 nozzle",
43
+ "process": "0.20mm Standard @BBL A1",
44
+ "filament": "Bambu PLA Basic @BBL A1",
45
+ },
46
+ file="cube.stl", # a path, bytes, or a binary file object
47
+ )
48
+
49
+ slice = client.slices.wait(slice["id"]) # polls until succeeded or failed
50
+
51
+ if slice["status"] == "succeeded":
52
+ result = slice["result"]
53
+ print(result["print_time_s"], "s")
54
+ print(result["filament_g"], "g")
55
+ if slice["price"]:
56
+ print(slice["price"]["total_minor"], slice["price"]["currency"]) # integer minor units
57
+ else:
58
+ print("failed:", slice["error"]["code"])
59
+ ```
60
+
61
+ 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.
62
+
63
+ `AsyncSuperslice` has the same methods as coroutines:
64
+
65
+ ```python
66
+ import asyncio
67
+ from superslice import AsyncSuperslice
68
+
69
+ async def main():
70
+ async with AsyncSuperslice() as client:
71
+ s = await client.slices.create(params, file="cube.stl")
72
+ s = await client.slices.wait(s["id"])
73
+ async for item in client.slices.list_all():
74
+ print(item["id"])
75
+
76
+ asyncio.run(main())
77
+ ```
78
+
79
+ 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.
80
+
81
+ ## Catalogue lookup
82
+
83
+ ```python
84
+ engines = client.engines.list()["data"]
85
+ release = next(e["id"] for e in engines if e["slicer"] == "bambu-studio" and e["status"] == "active")
86
+
87
+ printers = client.engines.printers(release)["data"]
88
+ name = printers[0]["name"]
89
+ client.engines.processes(release, name)
90
+ client.engines.filaments(release, name)
91
+ client.engines.plate_types(release, name)
92
+ ```
93
+
94
+ Releases contain `@` and `+`. The library percent-encodes them for you.
95
+
96
+ ## Idempotency
97
+
98
+ Pass a key and a repeated call returns the same slice instead of slicing again:
99
+
100
+ ```python
101
+ client.slices.create(params, file="cube.stl", idempotency_key="order-1042")
102
+ ```
103
+
104
+ The same key with a different body raises `ConflictError` with code `idempotency_conflict`.
105
+
106
+ ## Errors
107
+
108
+ Every error extends `SupersliceError` and carries `status`, `code`, `title`, `errors`, `retry_after` and the raw `body`.
109
+
110
+ | Class | When |
111
+ |---|---|
112
+ | `AuthenticationError` | 401 |
113
+ | `PermissionError` | 403 |
114
+ | `NotFoundError` | 404 |
115
+ | `ConflictError` | 409 |
116
+ | `RateLimitError` | 429 |
117
+ | `InvalidRequestError` | 400, 413 |
118
+ | `PlanLimitError` | 402 |
119
+ | `ServerError` | 5xx |
120
+ | `APIConnectionError` | no response |
121
+ | `APITimeoutError` | request timeout, or `slices.wait` ran out of time |
122
+
123
+ ```python
124
+ from superslice import InvalidRequestError, NotFoundError
125
+
126
+ try:
127
+ client.slices.get("slc_missing")
128
+ except NotFoundError as e:
129
+ print(e.status, e.code)
130
+ except InvalidRequestError as e:
131
+ print(e.errors) # [{"path": ..., "message": ...}]
132
+ ```
133
+
134
+ `PermissionError` shadows the builtin of the same name inside any module that imports it from `superslice`. Use `superslice.PermissionError` if that matters.
135
+
136
+ A slice that fails is not an exception. `slices.wait` returns it with `status == "failed"` and `error` set.
137
+
138
+ ## Retries
139
+
140
+ 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.
141
+
142
+ `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.
143
+
144
+ ## Webhooks
145
+
146
+ Verify the `Superslice-Signature` header against the raw request body, before parsing JSON:
147
+
148
+ ```python
149
+ from superslice import Webhooks, SignatureVerificationError
150
+
151
+ try:
152
+ event = Webhooks.verify(secret, request.headers["Superslice-Signature"], raw_body)
153
+ except SignatureVerificationError:
154
+ return 400
155
+ if event["event"] == "slice.completed":
156
+ print(event["data"]["result"]["print_time_s"])
157
+ ```
158
+
159
+ `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`.
160
+
161
+ ## Configuration
162
+
163
+ ```python
164
+ Superslice(
165
+ api_key="sk_...", # default: SUPERSLICE_API_KEY
166
+ base_url="https://api.superslice.co", # default
167
+ timeout=60.0, # seconds
168
+ max_retries=2,
169
+ )
170
+ ```
171
+
172
+ 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()`.
173
+
174
+ Other resources: `client.models`, `client.presets`, `client.pricing`, `client.slicers`.
175
+
176
+ ## Links
177
+
178
+ - Docs: https://docs.superslice.co
179
+ - API reference: https://docs.superslice.co/api/post-slices
180
+ - Status: https://status.superslice.co
181
+ - Support: hello@superslice.co
182
+
183
+ MIT licence.
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "superslice"
7
+ version = "0.1.0"
8
+ description = "Official Python library for the Superslice API"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.10"
12
+ dependencies = ["httpx>=0.24,<1"]
13
+ keywords = ["superslice", "3d-printing", "slicer", "api-client", "sdk"]
14
+ classifiers = [
15
+ "Typing :: Typed",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.10",
18
+ "Programming Language :: Python :: 3.11",
19
+ "Programming Language :: Python :: 3.12",
20
+ "Programming Language :: Python :: 3.13",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://docs.superslice.co"
25
+ Repository = "https://github.com/superslice-co/superslice-python"
26
+
27
+ [project.optional-dependencies]
28
+ dev = ["pytest", "pytest-asyncio", "mypy"]
29
+
30
+ [tool.hatch.build.targets.wheel]
31
+ packages = ["src/superslice"]
32
+
33
+ [tool.pytest.ini_options]
34
+ asyncio_mode = "auto"
35
+ testpaths = ["tests"]
36
+
37
+ [tool.mypy]
38
+ strict = true
39
+ files = ["src"]
@@ -0,0 +1,37 @@
1
+ from ._async import AsyncSuperslice
2
+ from ._core import __version__
3
+ from ._sync import Superslice
4
+ from .errors import (
5
+ APIConnectionError,
6
+ APITimeoutError,
7
+ AuthenticationError,
8
+ ConflictError,
9
+ InvalidRequestError,
10
+ NotFoundError,
11
+ PermissionError,
12
+ PlanLimitError,
13
+ RateLimitError,
14
+ ServerError,
15
+ SignatureVerificationError,
16
+ SupersliceError,
17
+ )
18
+ from .webhooks import Webhooks
19
+
20
+ __all__ = [
21
+ "Superslice",
22
+ "AsyncSuperslice",
23
+ "Webhooks",
24
+ "SupersliceError",
25
+ "AuthenticationError",
26
+ "PermissionError",
27
+ "NotFoundError",
28
+ "ConflictError",
29
+ "RateLimitError",
30
+ "InvalidRequestError",
31
+ "PlanLimitError",
32
+ "ServerError",
33
+ "APIConnectionError",
34
+ "APITimeoutError",
35
+ "SignatureVerificationError",
36
+ "__version__",
37
+ ]