inkwire-client 0.1.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.
@@ -0,0 +1,46 @@
1
+ import time
2
+ import httpx
3
+
4
+ _transport = None # tests may inject an httpx.MockTransport
5
+
6
+
7
+ class InkwireClientError(Exception):
8
+ def __init__(self, code: str, message: str, http_status: int):
9
+ super().__init__(message)
10
+ self.code = code
11
+ self.message = message
12
+ self.http_status = http_status
13
+
14
+
15
+ def publish(base_url: str, api_key: str, payload: dict, retries: int = 3) -> dict:
16
+ # ponytail: clamp retries to ensure loop executes at least once
17
+ retries = max(1, retries)
18
+
19
+ url = base_url.rstrip("/") + "/api/posts"
20
+ headers = {
21
+ "content-type": "application/json",
22
+ "authorization": f"Bearer {api_key}",
23
+ "idempotency-key": payload["external_id"],
24
+ }
25
+ client = httpx.Client(transport=_transport) if _transport else httpx.Client()
26
+ try:
27
+ last = None
28
+ for attempt in range(1, retries + 1):
29
+ res = client.post(url, json=payload, headers=headers)
30
+ if res.status_code == 200:
31
+ return res.json()
32
+ retriable = res.status_code == 429 or res.status_code >= 500
33
+ code, message = "internal", f"HTTP {res.status_code}"
34
+ try:
35
+ err = res.json().get("error")
36
+ if err:
37
+ code, message = err["code"], err["message"]
38
+ except Exception:
39
+ pass
40
+ if not retriable or attempt == retries:
41
+ raise InkwireClientError(code, message, res.status_code)
42
+ last = InkwireClientError(code, message, res.status_code)
43
+ time.sleep(2 ** (attempt - 1) * 0.2)
44
+ raise last
45
+ finally:
46
+ client.close()
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: inkwire-client
3
+ Version: 0.1.0
4
+ Summary: Client SDK for publishing posts to an Inkwire receiver (idempotent, retrying, typed errors).
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/etugrand/inkwire
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: httpx>=0.27
10
+ Provides-Extra: dev
11
+ Requires-Dist: pytest>=8.3; extra == "dev"
12
+
13
+ # inkwire-client
14
+
15
+ Python client for publishing posts to an [Inkwire](https://github.com/etugrand/inkwire) receiver.
16
+
17
+ ```python
18
+ from inkwire_client import publish
19
+
20
+ result = publish("https://blog.example.com", "your-api-key", {
21
+ "external_id": "my-post-1",
22
+ "title": "Hello",
23
+ "markdown": "# Hello\n\nFirst post via Inkwire.",
24
+ "status": "published",
25
+ })
26
+ ```
27
+
28
+ `publish(base_url, api_key, payload, retries=3)` upserts by `external_id`, retries on `429`/5xx with backoff, and raises `InkwireClientError(code, message, http_status)` on failure.
29
+
30
+ See the [protocol spec](https://github.com/etugrand/inkwire/blob/master/inkwire/SPEC.md) for the full payload shape.
@@ -0,0 +1,5 @@
1
+ inkwire_client/__init__.py,sha256=zvB3smoxJM106cE2mNcxU_TvWiMF8VZJh9W3n9sXGhc,1651
2
+ inkwire_client-0.1.0.dist-info/METADATA,sha256=oSUV2bioXLwjhjAHQaYGxOWf4et4Hfbm9ndZqkMdsnI,1069
3
+ inkwire_client-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
4
+ inkwire_client-0.1.0.dist-info/top_level.txt,sha256=BzJhbzFW-14VDVQQb-EXpoyCFvg6pz47pJSdeTSNn8A,15
5
+ inkwire_client-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ inkwire_client