inkwire-client 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.
@@ -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,18 @@
1
+ # inkwire-client
2
+
3
+ Python client for publishing posts to an [Inkwire](https://github.com/etugrand/inkwire) receiver.
4
+
5
+ ```python
6
+ from inkwire_client import publish
7
+
8
+ result = publish("https://blog.example.com", "your-api-key", {
9
+ "external_id": "my-post-1",
10
+ "title": "Hello",
11
+ "markdown": "# Hello\n\nFirst post via Inkwire.",
12
+ "status": "published",
13
+ })
14
+ ```
15
+
16
+ `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.
17
+
18
+ See the [protocol spec](https://github.com/etugrand/inkwire/blob/master/inkwire/SPEC.md) for the full payload shape.
@@ -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,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ inkwire_client/__init__.py
4
+ inkwire_client.egg-info/PKG-INFO
5
+ inkwire_client.egg-info/SOURCES.txt
6
+ inkwire_client.egg-info/dependency_links.txt
7
+ inkwire_client.egg-info/requires.txt
8
+ inkwire_client.egg-info/top_level.txt
9
+ tests/test_client.py
@@ -0,0 +1,4 @@
1
+ httpx>=0.27
2
+
3
+ [dev]
4
+ pytest>=8.3
@@ -0,0 +1 @@
1
+ inkwire_client
@@ -0,0 +1,21 @@
1
+ [project]
2
+ name = "inkwire-client"
3
+ version = "0.1.0"
4
+ description = "Client SDK for publishing posts to an Inkwire receiver (idempotent, retrying, typed errors)."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ requires-python = ">=3.11"
8
+ dependencies = ["httpx>=0.27"]
9
+
10
+ [project.urls]
11
+ Repository = "https://github.com/etugrand/inkwire"
12
+
13
+ [project.optional-dependencies]
14
+ dev = ["pytest>=8.3"]
15
+
16
+ [tool.setuptools.packages.find]
17
+ include = ["inkwire_client*"]
18
+
19
+ [build-system]
20
+ requires = ["setuptools>=61"]
21
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,46 @@
1
+ import httpx
2
+ import pytest
3
+ from inkwire_client import publish, InkwireClientError
4
+
5
+
6
+ def make_transport(responses):
7
+ calls = {"n": 0}
8
+ def handler(request):
9
+ i = min(calls["n"], len(responses) - 1)
10
+ calls["n"] += 1
11
+ status, body = responses[i]
12
+ return httpx.Response(status, json=body, headers={"inkwire-version": "1"})
13
+ return httpx.MockTransport(handler), calls
14
+
15
+
16
+ def test_publish_ok(monkeypatch):
17
+ transport, calls = make_transport([(200, {"id": "1", "external_id": "e", "url": "u", "slug": "s", "status": "published", "created": True})])
18
+ monkeypatch.setattr("inkwire_client._transport", transport, raising=False)
19
+ r = publish("https://site.test", "k", {"external_id": "e", "title": "T", "markdown": "x"}, retries=1)
20
+ assert r["created"] is True
21
+
22
+
23
+ def test_retry_then_success(monkeypatch):
24
+ transport, calls = make_transport([(500, {}), (200, {"id": "1", "external_id": "e", "url": "u", "slug": "s", "status": "draft", "created": True})])
25
+ monkeypatch.setattr("inkwire_client._transport", transport, raising=False)
26
+ r = publish("https://site.test", "k", {"external_id": "e", "title": "T", "markdown": "x"}, retries=3)
27
+ assert r["id"] == "1" and calls["n"] == 2
28
+
29
+
30
+ def test_401_raises(monkeypatch):
31
+ transport, calls = make_transport([(401, {"error": {"code": "unauthorized", "message": "no"}})])
32
+ monkeypatch.setattr("inkwire_client._transport", transport, raising=False)
33
+ with pytest.raises(InkwireClientError) as ei:
34
+ publish("https://site.test", "bad", {"external_id": "e", "title": "T", "markdown": "x"})
35
+ assert ei.value.code == "unauthorized" and calls["n"] == 1
36
+
37
+
38
+ def test_retries_zero_makes_one_request(monkeypatch):
39
+ """Verify retries=0 makes exactly one request and raises proper InkwireClientError, not TypeError."""
40
+ transport, calls = make_transport([(500, {"error": {"code": "server_error", "message": "Internal Server Error"}})])
41
+ monkeypatch.setattr("inkwire_client._transport", transport, raising=False)
42
+ with pytest.raises(InkwireClientError) as ei:
43
+ publish("https://site.test", "k", {"external_id": "e", "title": "T", "markdown": "x"}, retries=0)
44
+ assert ei.value.code == "server_error"
45
+ assert ei.value.http_status == 500
46
+ assert calls["n"] == 1 # exactly one request made