printit-sdk 1.0.0__py3-none-any.whl
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.
- printit/__init__.py +19 -0
- printit/client.py +297 -0
- printit/supply.py +81 -0
- printit/types.py +53 -0
- printit_sdk-1.0.0.dist-info/METADATA +114 -0
- printit_sdk-1.0.0.dist-info/RECORD +9 -0
- printit_sdk-1.0.0.dist-info/WHEEL +5 -0
- printit_sdk-1.0.0.dist-info/licenses/LICENSE +21 -0
- printit_sdk-1.0.0.dist-info/top_level.txt +1 -0
printit/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Print It Python SDK
|
|
3
|
+
===================
|
|
4
|
+
Not yet on PyPI — install from the repository (packages/sdk/python).
|
|
5
|
+
|
|
6
|
+
Quick start:
|
|
7
|
+
from printit import PrintIt
|
|
8
|
+
|
|
9
|
+
client = PrintIt(api_key="sk_pi_test_...") # test mode: nothing is charged
|
|
10
|
+
quote = client.quote("bracket.stl", delivery_lat=40.71, delivery_lon=-74.0, ship_to={...})
|
|
11
|
+
order = client.order(quote["order_id"])
|
|
12
|
+
status = client.status(order["order_id"])
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from .client import PrintIt, PrintItError, QuoteResult, OrderResult, StatusResult
|
|
16
|
+
from .supply import PrintItSupply
|
|
17
|
+
|
|
18
|
+
__version__ = "1.0.0"
|
|
19
|
+
__all__ = ["PrintIt", "PrintItError", "PrintItSupply", "QuoteResult", "OrderResult", "StatusResult"]
|
printit/client.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"""
|
|
2
|
+
PrintIt client — synchronous and async interfaces.
|
|
3
|
+
|
|
4
|
+
Sync:
|
|
5
|
+
client = PrintIt(api_key="sk_pi_test_...") # a TEST key: nothing is charged
|
|
6
|
+
quote = client.quote("model.stl", delivery_lat=40.71, delivery_lon=-74.0,
|
|
7
|
+
ship_to={"name": "Ada", "street": "1 Main St", "city": "New York",
|
|
8
|
+
"postal_code": "10001", "country_code": "US"})
|
|
9
|
+
client.order(quote["order_id"]) # the quoted address is used
|
|
10
|
+
client.advance(quote["order_id"]) # test mode: next production step
|
|
11
|
+
|
|
12
|
+
Async:
|
|
13
|
+
async with PrintIt(api_key="sk_pi_...") as client:
|
|
14
|
+
quote = await client.quote_async("model.stl", delivery_lat=40.71, delivery_lon=-74.0)
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
from pathlib import Path
|
|
21
|
+
from typing import Any, Optional
|
|
22
|
+
|
|
23
|
+
import httpx
|
|
24
|
+
|
|
25
|
+
from .types import OrderResult, QuoteResult, StatusResult
|
|
26
|
+
|
|
27
|
+
TEST_KEY_PREFIX = "sk_pi_test_"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class PrintItError(Exception):
|
|
31
|
+
"""Raised for API errors with status >= 400. Branch on ``code`` (e.g.
|
|
32
|
+
``insufficient_balance``, ``requote_required``, ``cancel_not_allowed``)."""
|
|
33
|
+
|
|
34
|
+
def __init__(self, status_code: int, detail: Any) -> None:
|
|
35
|
+
self.status_code = status_code
|
|
36
|
+
self.detail = detail
|
|
37
|
+
self.code = detail.get("error") if isinstance(detail, dict) else None
|
|
38
|
+
super().__init__(f"PrintIt API error {status_code}: {detail}")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
_DEFAULT_BASE_URL = "https://api.printit.dev"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _quote_form(*, delivery_lat, delivery_lon, material, color, quantity, infill_percent,
|
|
45
|
+
layer_height_mm, supports, wall_shells, is_urgent, currency, ship_to) -> dict:
|
|
46
|
+
data = {
|
|
47
|
+
"material": material,
|
|
48
|
+
"color": color,
|
|
49
|
+
"quantity": str(quantity),
|
|
50
|
+
"infill_percent": str(infill_percent),
|
|
51
|
+
"layer_height_mm": str(layer_height_mm),
|
|
52
|
+
"supports": supports,
|
|
53
|
+
"wall_shells": str(wall_shells),
|
|
54
|
+
"is_urgent": str(is_urgent).lower(),
|
|
55
|
+
"currency": currency,
|
|
56
|
+
}
|
|
57
|
+
if delivery_lat is not None and delivery_lon is not None:
|
|
58
|
+
data["delivery_lat"], data["delivery_lon"] = str(delivery_lat), str(delivery_lon)
|
|
59
|
+
elif not ship_to:
|
|
60
|
+
raise ValueError("Pass ship_to (the delivery address) or delivery_lat + delivery_lon.")
|
|
61
|
+
if ship_to:
|
|
62
|
+
data["ship_to"] = json.dumps(ship_to)
|
|
63
|
+
return data
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class PrintIt:
|
|
67
|
+
"""
|
|
68
|
+
Print It SDK client.
|
|
69
|
+
|
|
70
|
+
Parameters
|
|
71
|
+
----------
|
|
72
|
+
api_key : str
|
|
73
|
+
``sk_pi_test_…`` (test mode: real quotes, nothing charged, no workshop) or
|
|
74
|
+
``sk_pi_…`` (live). Falls back to the PRINTIT_API_KEY env var.
|
|
75
|
+
base_url : str
|
|
76
|
+
Override for self-hosted instances. Defaults to https://api.printit.dev.
|
|
77
|
+
timeout : float
|
|
78
|
+
HTTP timeout in seconds (default 120 — uploads can be slow).
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
def __init__(
|
|
82
|
+
self,
|
|
83
|
+
api_key: Optional[str] = None,
|
|
84
|
+
base_url: str = _DEFAULT_BASE_URL,
|
|
85
|
+
timeout: float = 120.0,
|
|
86
|
+
) -> None:
|
|
87
|
+
self._api_key = api_key or os.environ.get("PRINTIT_API_KEY", "")
|
|
88
|
+
if not self._api_key:
|
|
89
|
+
raise ValueError(
|
|
90
|
+
"api_key is required. Pass it directly or set the PRINTIT_API_KEY env var."
|
|
91
|
+
)
|
|
92
|
+
self._base_url = base_url.rstrip("/")
|
|
93
|
+
self._timeout = timeout
|
|
94
|
+
self._headers = {"X-PrintIt-Key": self._api_key}
|
|
95
|
+
|
|
96
|
+
@property
|
|
97
|
+
def livemode(self) -> bool:
|
|
98
|
+
"""False for a test key — its orders never charge money or reach a workshop."""
|
|
99
|
+
return not self._api_key.startswith(TEST_KEY_PREFIX)
|
|
100
|
+
|
|
101
|
+
def _h(self, idempotency_key: Optional[str]) -> dict:
|
|
102
|
+
return {**self._headers, **({"X-Idempotency-Key": idempotency_key} if idempotency_key else {})}
|
|
103
|
+
|
|
104
|
+
def _url(self, path: str) -> str:
|
|
105
|
+
return f"{self._base_url}{path}"
|
|
106
|
+
|
|
107
|
+
# ── Sync API ──────────────────────────────────────────────────────────────
|
|
108
|
+
|
|
109
|
+
def quote(
|
|
110
|
+
self,
|
|
111
|
+
file_path: str | Path,
|
|
112
|
+
*,
|
|
113
|
+
delivery_lat: Optional[float] = None,
|
|
114
|
+
delivery_lon: Optional[float] = None,
|
|
115
|
+
material: str = "pla_standard",
|
|
116
|
+
color: str = "White",
|
|
117
|
+
quantity: int = 1,
|
|
118
|
+
infill_percent: int = 20,
|
|
119
|
+
layer_height_mm: float = 0.2,
|
|
120
|
+
supports: str = "standard",
|
|
121
|
+
wall_shells: int = 2,
|
|
122
|
+
is_urgent: bool = False,
|
|
123
|
+
currency: str = "USD",
|
|
124
|
+
ship_to: Optional[dict] = None,
|
|
125
|
+
idempotency_key: Optional[str] = None,
|
|
126
|
+
) -> QuoteResult:
|
|
127
|
+
"""Upload a 3D file and receive a binding quote. With ``ship_to`` the shipping line
|
|
128
|
+
is priced to that street (``shipping.basis == "exact"``), the coordinates are optional
|
|
129
|
+
(the address is placed for you) and ``order`` needs no address; without it, pass the
|
|
130
|
+
coordinates and shipping is an estimate."""
|
|
131
|
+
path = Path(file_path)
|
|
132
|
+
if not path.exists():
|
|
133
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
134
|
+
data = _quote_form(delivery_lat=delivery_lat, delivery_lon=delivery_lon, material=material,
|
|
135
|
+
color=color, quantity=quantity, infill_percent=infill_percent,
|
|
136
|
+
layer_height_mm=layer_height_mm, supports=supports,
|
|
137
|
+
wall_shells=wall_shells, is_urgent=is_urgent, currency=currency,
|
|
138
|
+
ship_to=ship_to)
|
|
139
|
+
with httpx.Client(timeout=self._timeout) as client, path.open("rb") as f:
|
|
140
|
+
response = client.post(self._url("/v1/quote"), headers=self._h(idempotency_key),
|
|
141
|
+
files={"file": (path.name, f, "application/octet-stream")},
|
|
142
|
+
data=data)
|
|
143
|
+
return _json(response)
|
|
144
|
+
|
|
145
|
+
def order(
|
|
146
|
+
self,
|
|
147
|
+
order_id: str,
|
|
148
|
+
*,
|
|
149
|
+
ship_to: Optional[dict] = None,
|
|
150
|
+
idempotency_key: Optional[str] = None,
|
|
151
|
+
) -> OrderResult:
|
|
152
|
+
"""Pay from your wallet and dispatch a quoted order (nothing is charged in test mode).
|
|
153
|
+
|
|
154
|
+
``ship_to`` — ``{"name", "street", "city", "postal_code", "country_code", "region"?,
|
|
155
|
+
"phone"?, "instructions"?}``. Optional when the quote carried one (it may repeat it,
|
|
156
|
+
never move it — ``requote_required``); required otherwise."""
|
|
157
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
158
|
+
response = client.post(self._url(f"/v1/route/{order_id}"), headers=self._h(idempotency_key),
|
|
159
|
+
json={"ship_to": ship_to} if ship_to else {})
|
|
160
|
+
return _json(response)
|
|
161
|
+
|
|
162
|
+
def order_parts(self, order_ids: list[str], *, ship_to: Optional[dict] = None,
|
|
163
|
+
accept_new_totals: bool = False,
|
|
164
|
+
idempotency_key: Optional[str] = None) -> dict:
|
|
165
|
+
"""Route a parts list (2–50 quoted parts) as ONE order: one address, the fewest boxes,
|
|
166
|
+
one charge per part — all or nothing. If packing them together would raise a part's
|
|
167
|
+
price, nothing is charged and ``PrintItError.code == "requote_required"`` carries the
|
|
168
|
+
new figures; pass ``accept_new_totals=True`` to route at them."""
|
|
169
|
+
body: dict = {"order_ids": list(order_ids)}
|
|
170
|
+
if ship_to:
|
|
171
|
+
body["ship_to"] = ship_to
|
|
172
|
+
if accept_new_totals:
|
|
173
|
+
body["accept_new_totals"] = True
|
|
174
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
175
|
+
response = client.post(self._url("/v1/route"), headers=self._h(idempotency_key), json=body)
|
|
176
|
+
return _json(response)
|
|
177
|
+
|
|
178
|
+
def status(self, order_id: str) -> StatusResult:
|
|
179
|
+
"""One order: status, the contract, the promised delivery date and the courier."""
|
|
180
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
181
|
+
response = client.get(self._url(f"/v1/orders/{order_id}"), headers=self._headers)
|
|
182
|
+
return _json(response)
|
|
183
|
+
|
|
184
|
+
def cancel(self, order_id: str, *, reason: Optional[str] = None,
|
|
185
|
+
idempotency_key: Optional[str] = None) -> dict:
|
|
186
|
+
"""Cancel before a workshop accepts it; a paid order's price returns to your wallet.
|
|
187
|
+
Safe to retry. A started order raises ``PrintItError`` with code ``cancel_not_allowed``."""
|
|
188
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
189
|
+
response = client.post(self._url(f"/v1/orders/{order_id}/cancel"),
|
|
190
|
+
headers=self._h(idempotency_key),
|
|
191
|
+
json={"reason": reason} if reason else {})
|
|
192
|
+
return _json(response)
|
|
193
|
+
|
|
194
|
+
def advance(self, order_id: str, to: Optional[str] = None) -> StatusResult:
|
|
195
|
+
"""TEST MODE ONLY — move a test order to its next state (or ``to``), exactly as a
|
|
196
|
+
real one would travel; your webhook receives each step with ``livemode: false``."""
|
|
197
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
198
|
+
response = client.post(self._url(f"/v1/test/orders/{order_id}/advance"),
|
|
199
|
+
headers=self._headers, json={"to": to} if to else {})
|
|
200
|
+
return _json(response)
|
|
201
|
+
|
|
202
|
+
def materials(self, technology: Optional[str] = None) -> list[dict]:
|
|
203
|
+
"""List available materials. Optionally filter by technology (FDM, SLA)."""
|
|
204
|
+
params = {"technology": technology.upper()} if technology else {}
|
|
205
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
206
|
+
response = client.get(self._url("/v1/materials"), headers=self._headers, params=params)
|
|
207
|
+
return _json(response)
|
|
208
|
+
|
|
209
|
+
def webhook_status(self, order_id: str) -> dict:
|
|
210
|
+
"""Get outbound webhook delivery status for an order (DLQ inspection)."""
|
|
211
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
212
|
+
response = client.get(self._url(f"/v1/webhooks/status/{order_id}"), headers=self._headers)
|
|
213
|
+
return _json(response)
|
|
214
|
+
|
|
215
|
+
# ── Async API ─────────────────────────────────────────────────────────────
|
|
216
|
+
|
|
217
|
+
async def quote_async(
|
|
218
|
+
self,
|
|
219
|
+
file_path: str | Path,
|
|
220
|
+
*,
|
|
221
|
+
delivery_lat: Optional[float] = None,
|
|
222
|
+
delivery_lon: Optional[float] = None,
|
|
223
|
+
material: str = "pla_standard",
|
|
224
|
+
color: str = "White",
|
|
225
|
+
quantity: int = 1,
|
|
226
|
+
infill_percent: int = 20,
|
|
227
|
+
layer_height_mm: float = 0.2,
|
|
228
|
+
supports: str = "standard",
|
|
229
|
+
wall_shells: int = 2,
|
|
230
|
+
is_urgent: bool = False,
|
|
231
|
+
currency: str = "USD",
|
|
232
|
+
ship_to: Optional[dict] = None,
|
|
233
|
+
idempotency_key: Optional[str] = None,
|
|
234
|
+
) -> QuoteResult:
|
|
235
|
+
path = Path(file_path)
|
|
236
|
+
if not path.exists():
|
|
237
|
+
raise FileNotFoundError(f"File not found: {file_path}")
|
|
238
|
+
data = _quote_form(delivery_lat=delivery_lat, delivery_lon=delivery_lon, material=material,
|
|
239
|
+
color=color, quantity=quantity, infill_percent=infill_percent,
|
|
240
|
+
layer_height_mm=layer_height_mm, supports=supports,
|
|
241
|
+
wall_shells=wall_shells, is_urgent=is_urgent, currency=currency,
|
|
242
|
+
ship_to=ship_to)
|
|
243
|
+
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
|
244
|
+
with path.open("rb") as f:
|
|
245
|
+
response = await client.post(
|
|
246
|
+
self._url("/v1/quote"), headers=self._h(idempotency_key),
|
|
247
|
+
files={"file": (path.name, f, "application/octet-stream")}, data=data)
|
|
248
|
+
return _json(response)
|
|
249
|
+
|
|
250
|
+
async def order_async(
|
|
251
|
+
self,
|
|
252
|
+
order_id: str,
|
|
253
|
+
*,
|
|
254
|
+
ship_to: Optional[dict] = None,
|
|
255
|
+
idempotency_key: Optional[str] = None,
|
|
256
|
+
) -> OrderResult:
|
|
257
|
+
"""Async ``order`` — see ``order`` for ``ship_to``."""
|
|
258
|
+
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
|
259
|
+
response = await client.post(self._url(f"/v1/route/{order_id}"),
|
|
260
|
+
headers=self._h(idempotency_key),
|
|
261
|
+
json={"ship_to": ship_to} if ship_to else {})
|
|
262
|
+
return _json(response)
|
|
263
|
+
|
|
264
|
+
async def status_async(self, order_id: str) -> StatusResult:
|
|
265
|
+
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
|
266
|
+
response = await client.get(self._url(f"/v1/orders/{order_id}"), headers=self._headers)
|
|
267
|
+
return _json(response)
|
|
268
|
+
|
|
269
|
+
async def cancel_async(self, order_id: str, *, reason: Optional[str] = None,
|
|
270
|
+
idempotency_key: Optional[str] = None) -> dict:
|
|
271
|
+
async with httpx.AsyncClient(timeout=self._timeout) as client:
|
|
272
|
+
response = await client.post(self._url(f"/v1/orders/{order_id}/cancel"),
|
|
273
|
+
headers=self._h(idempotency_key),
|
|
274
|
+
json={"reason": reason} if reason else {})
|
|
275
|
+
return _json(response)
|
|
276
|
+
|
|
277
|
+
# ── Context manager ───────────────────────────────────────────────────────
|
|
278
|
+
|
|
279
|
+
async def __aenter__(self) -> "PrintIt":
|
|
280
|
+
return self
|
|
281
|
+
|
|
282
|
+
async def __aexit__(self, *_: Any) -> None:
|
|
283
|
+
pass
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _raise_for_status(response: httpx.Response) -> None:
|
|
287
|
+
if response.status_code >= 400:
|
|
288
|
+
try:
|
|
289
|
+
detail = response.json().get("detail", response.text)
|
|
290
|
+
except Exception:
|
|
291
|
+
detail = response.text
|
|
292
|
+
raise PrintItError(response.status_code, detail)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def _json(response: httpx.Response) -> Any:
|
|
296
|
+
_raise_for_status(response)
|
|
297
|
+
return response.json()
|
printit/supply.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The Supply API — for a workshop's own software (a print farm's MES, a bureau's scheduler).
|
|
3
|
+
|
|
4
|
+
from printit import PrintItSupply
|
|
5
|
+
|
|
6
|
+
farm = PrintItSupply(api_key="sk_pi_supply_...") # minted by the maker at printit.dev/developers
|
|
7
|
+
for offer in farm.offers(): # the platform's order — keep it
|
|
8
|
+
if fits_my_queue(offer):
|
|
9
|
+
farm.claim(offer["order_id"]) # accepting is starting
|
|
10
|
+
break
|
|
11
|
+
farm.download(order_id, "part.stl")
|
|
12
|
+
farm.printed(order_id, actual_weight_grams=41.5)
|
|
13
|
+
farm.ship(order_id) # the platform picks the courier
|
|
14
|
+
|
|
15
|
+
A workshop key acts as the maker on these endpoints only: it never places orders and is never
|
|
16
|
+
a login. One job per claim — there is no bulk claim.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any, Optional
|
|
23
|
+
|
|
24
|
+
import httpx
|
|
25
|
+
|
|
26
|
+
from .client import _DEFAULT_BASE_URL, _json
|
|
27
|
+
|
|
28
|
+
SUPPLY_KEY_PREFIX = "sk_pi_supply_"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class PrintItSupply:
|
|
32
|
+
def __init__(self, api_key: Optional[str] = None, base_url: str = _DEFAULT_BASE_URL,
|
|
33
|
+
timeout: float = 120.0) -> None:
|
|
34
|
+
self._api_key = api_key or os.environ.get("PRINTIT_SUPPLY_KEY", "")
|
|
35
|
+
if not self._api_key.startswith(SUPPLY_KEY_PREFIX):
|
|
36
|
+
raise ValueError("A workshop key (sk_pi_supply_…) is required — pass it or set PRINTIT_SUPPLY_KEY.")
|
|
37
|
+
self._base_url = base_url.rstrip("/")
|
|
38
|
+
self._timeout = timeout
|
|
39
|
+
self._headers = {"X-PrintIt-Key": self._api_key}
|
|
40
|
+
|
|
41
|
+
def _call(self, method: str, path: str, json: Optional[dict] = None) -> Any:
|
|
42
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
43
|
+
response = client.request(method, f"{self._base_url}/v1/supply{path}",
|
|
44
|
+
headers=self._headers, json=json)
|
|
45
|
+
return _json(response)
|
|
46
|
+
|
|
47
|
+
def offers(self) -> Any:
|
|
48
|
+
"""Jobs offered to this workshop, ranked by the platform."""
|
|
49
|
+
return self._call("GET", "/offers")
|
|
50
|
+
|
|
51
|
+
def offer(self, order_id: str) -> Any:
|
|
52
|
+
"""One job: the buyer's paid spec, the part's size, the deadlines."""
|
|
53
|
+
return self._call("GET", f"/offers/{order_id}")
|
|
54
|
+
|
|
55
|
+
def claim(self, order_id: str) -> Any:
|
|
56
|
+
"""Claim one job. Raises PrintItError 409 if another workshop took it first."""
|
|
57
|
+
return self._call("POST", f"/offers/{order_id}/claim")
|
|
58
|
+
|
|
59
|
+
def jobs(self) -> Any:
|
|
60
|
+
"""This workshop's jobs in progress."""
|
|
61
|
+
return self._call("GET", "/jobs")
|
|
62
|
+
|
|
63
|
+
def download(self, order_id: str, dest: str | Path) -> Path:
|
|
64
|
+
"""Save the part's file to `dest`."""
|
|
65
|
+
with httpx.Client(timeout=self._timeout) as client:
|
|
66
|
+
response = client.get(f"{self._base_url}/v1/supply/jobs/{order_id}/file", headers=self._headers)
|
|
67
|
+
if response.status_code >= 400:
|
|
68
|
+
_json(response) # raises PrintItError with the API's detail
|
|
69
|
+
path = Path(dest)
|
|
70
|
+
path.write_bytes(response.content)
|
|
71
|
+
return path
|
|
72
|
+
|
|
73
|
+
def printed(self, order_id: str, *, actual_weight_grams: Optional[float] = None) -> Any:
|
|
74
|
+
"""Report the part printed and packed."""
|
|
75
|
+
body = {"actual_weight_grams": actual_weight_grams} if actual_weight_grams is not None else {}
|
|
76
|
+
return self._call("POST", f"/jobs/{order_id}/printed", json=body)
|
|
77
|
+
|
|
78
|
+
def ship(self, order_id: str, *, shipping_option_id: Optional[str] = None) -> Any:
|
|
79
|
+
"""Book the courier (None = the platform's recommended option)."""
|
|
80
|
+
body = {"shipping_option_id": shipping_option_id} if shipping_option_id else {}
|
|
81
|
+
return self._call("POST", f"/jobs/{order_id}/ship", json=body)
|
printit/types.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""The shapes the Print It API answers with (TypedDicts — keys as the API sends them)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from typing import Optional, TypedDict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class QuoteResult(TypedDict, total=False):
|
|
8
|
+
order_id: str
|
|
9
|
+
livemode: bool
|
|
10
|
+
status: str
|
|
11
|
+
geometry: dict
|
|
12
|
+
dfm: list
|
|
13
|
+
spec: dict # the contract: exactly what will be made
|
|
14
|
+
estimate: dict
|
|
15
|
+
pricing: dict # {currency, total_usd_cents, total_usd, total_display, markup_pct}
|
|
16
|
+
shipping: dict # {basis: "exact" | "estimate", ship_to}
|
|
17
|
+
delivery_promise: Optional[dict] # {days, hours, basis} or None (no honest promise)
|
|
18
|
+
coverage: dict
|
|
19
|
+
next_step: str
|
|
20
|
+
expires_at: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class OrderResult(TypedDict, total=False):
|
|
24
|
+
order_id: str
|
|
25
|
+
livemode: bool
|
|
26
|
+
status: str
|
|
27
|
+
coverage_type: str
|
|
28
|
+
charged_usd_cents: int
|
|
29
|
+
next_step: str
|
|
30
|
+
billing: str
|
|
31
|
+
dispatch_tier: str
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class StatusResult(TypedDict, total=False):
|
|
35
|
+
# No maker identity by design: /v1 is an order-solicitation API — Print It is
|
|
36
|
+
# accountable for the part, and naming the shop that printed it is how a
|
|
37
|
+
# customer learns to reorder around us. See the file-upload-engine
|
|
38
|
+
# `app/api/routers/v1.py` module header.
|
|
39
|
+
order_id: str
|
|
40
|
+
livemode: bool
|
|
41
|
+
status: str
|
|
42
|
+
message: str
|
|
43
|
+
accepted: bool
|
|
44
|
+
cancellable: bool
|
|
45
|
+
spec: dict
|
|
46
|
+
delivery: dict # {promised_by, promise}
|
|
47
|
+
courier: Optional[dict]
|
|
48
|
+
tracking: Optional[dict]
|
|
49
|
+
total_usd_cents: int
|
|
50
|
+
total_usd: float
|
|
51
|
+
currency: str
|
|
52
|
+
created_at: str
|
|
53
|
+
updated_at: str
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: printit-sdk
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the Print It on-demand 3D manufacturing API
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://printit.dev/developers
|
|
7
|
+
Project-URL: Documentation, https://printit.dev/docs
|
|
8
|
+
Keywords: 3d-printing,manufacturing,api,sdk
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: httpx>=0.27
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
22
|
+
Requires-Dist: respx; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# printit-sdk — Python client for the Print It API
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install printit-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Published by Make It Universal LLC, the company behind Print It. Get a key at
|
|
32
|
+
[printit.dev/developers](https://printit.dev/developers) — start with a **test** key
|
|
33
|
+
(`sk_pi_test_…`): real quotes, nothing charged, no workshop.
|
|
34
|
+
|
|
35
|
+
## Quick start (test mode — nothing is charged)
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from printit import PrintIt
|
|
39
|
+
|
|
40
|
+
client = PrintIt(api_key="sk_pi_test_...") # a test key: real quotes, no money, no workshop
|
|
41
|
+
|
|
42
|
+
ship_to = {"name": "Ada Lovelace", "street": "1 Main St", "city": "New York",
|
|
43
|
+
"region": "NY", "postal_code": "10001", "country_code": "US"}
|
|
44
|
+
|
|
45
|
+
# 1. Quote — the price, the contract and the delivery promise
|
|
46
|
+
quote = client.quote("bracket.stl", material="petg_pro", quantity=2, ship_to=ship_to)
|
|
47
|
+
# (an address is enough — pass delivery_lat/delivery_lon only if you have no address)
|
|
48
|
+
print(quote["pricing"]["total_display"], quote["shipping"]["basis"], quote["delivery_promise"])
|
|
49
|
+
print(quote["spec"]) # exactly what will be made
|
|
50
|
+
|
|
51
|
+
# 2. Route — pays from your wallet (live) and dispatches; the quoted address is used
|
|
52
|
+
client.order(quote["order_id"])
|
|
53
|
+
|
|
54
|
+
# 3. Test mode: walk it through production; your webhook gets every step
|
|
55
|
+
for _ in range(4):
|
|
56
|
+
print(client.advance(quote["order_id"])["status"]) # printing → … → delivered
|
|
57
|
+
|
|
58
|
+
# 4. Read it back
|
|
59
|
+
status = client.status(quote["order_id"])
|
|
60
|
+
print(status["status"], status["delivery"]["promised_by"], status["tracking"])
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Switch to a live key (`sk_pi_…`) and the same code charges your wallet and the job goes to
|
|
64
|
+
the network. `client.livemode` tells you which one you hold.
|
|
65
|
+
|
|
66
|
+
## A parts list is one order
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
ids = [client.quote(f, material="petg_pro", ship_to=ship_to)["order_id"] for f in kit_files]
|
|
70
|
+
out = client.order_parts(ids) # one address, the fewest boxes, all or nothing
|
|
71
|
+
print(out["shipments_planned"], out["shipping_saved_usd_cents"])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Cancel
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
client.cancel(order_id, reason="ordered_by_mistake") # before a workshop accepts it
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
A quote is withdrawn; a paid order's price returns to your wallet at once. Safe to retry.
|
|
81
|
+
|
|
82
|
+
## Async
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
async with PrintIt(api_key="sk_pi_...") as client:
|
|
86
|
+
quote = await client.quote_async("model.stl", delivery_lat=40.7, delivery_lon=-74.0)
|
|
87
|
+
await client.order_async(quote["order_id"], ship_to=ship_to)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Idempotent retries
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import uuid
|
|
94
|
+
idem = str(uuid.uuid4()) # generate once, reuse on every retry of the same call
|
|
95
|
+
client.order(order_id, idempotency_key=idem)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Errors
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from printit import PrintItError
|
|
102
|
+
|
|
103
|
+
try:
|
|
104
|
+
client.order(order_id)
|
|
105
|
+
except PrintItError as e:
|
|
106
|
+
if e.code == "insufficient_balance":
|
|
107
|
+
... # top up the wallet
|
|
108
|
+
elif e.code == "requote_required":
|
|
109
|
+
... # quote again with this ship_to
|
|
110
|
+
else:
|
|
111
|
+
print(e.status_code, e.detail)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`PRINTIT_API_KEY` in the environment is read when no `api_key` is passed.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
printit/__init__.py,sha256=BxuU5tzS7w14kes6FmPzwswz1q5UJhv_bDHDbjKfe6I,678
|
|
2
|
+
printit/client.py,sha256=CHXxyQUylgFcUUn5miSiSsUB2wv56cP43FNLeWTtKdA,13618
|
|
3
|
+
printit/supply.py,sha256=rytiz0UzuZfQj-JCriRhQGwDPEMOZ-cT8mCgg4u_tp0,3645
|
|
4
|
+
printit/types.py,sha256=0XznZU89kNcnMzpCj_DmjlFbONNRF0QuIt0VmdN-XIY,1570
|
|
5
|
+
printit_sdk-1.0.0.dist-info/licenses/LICENSE,sha256=jbcBCC9D_K96iycxlG6Xyl4n45k5pqDhvFhkY9F3Tg4,1078
|
|
6
|
+
printit_sdk-1.0.0.dist-info/METADATA,sha256=_dUXqlbmBBE_OkKXagVvixuxSCxxwpcKPbm-L0niqcs,3968
|
|
7
|
+
printit_sdk-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
+
printit_sdk-1.0.0.dist-info/top_level.txt,sha256=_L2Xq0dHfWyU6q4uhF7d-uvSGiJpdmmvIMAU7IPcgAo,8
|
|
9
|
+
printit_sdk-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Make It Universal LLC
|
|
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 @@
|
|
|
1
|
+
printit
|