mycommerce-platform 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.
mycommerce/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Public API for the mycommerce-platform package."""
2
+
3
+ from .client import ApiError, MyCommerceClient
4
+
5
+ __all__ = ["ApiError", "MyCommerceClient"]
6
+ __version__ = "0.1.0"
mycommerce/client.py ADDED
@@ -0,0 +1,83 @@
1
+ """Small standard-library-only client for the MyCommerce API gateway."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from dataclasses import dataclass
7
+ from typing import Any, Mapping
8
+ from urllib.error import HTTPError, URLError
9
+ from urllib.parse import urljoin
10
+ from urllib.request import Request, urlopen
11
+
12
+
13
+ class ApiError(RuntimeError):
14
+ """Raised when the gateway cannot return a successful JSON response."""
15
+
16
+ def __init__(self, status: int, message: str, payload: Any = None) -> None:
17
+ super().__init__(f"MyCommerce API error {status}: {message}")
18
+ self.status = status
19
+ self.payload = payload
20
+
21
+
22
+ @dataclass
23
+ class MyCommerceClient:
24
+ """Client for the Worker gateway and its three backend routes.
25
+
26
+ The gateway is expected to expose `/shop/*`, `/cart/*`, and `/purchase/*`.
27
+ The client does not contain service credentials; authentication is supplied
28
+ through the optional bearer token at request time or construction time.
29
+ """
30
+
31
+ base_url: str
32
+ token: str | None = None
33
+ timeout: float = 15.0
34
+
35
+ def _request(
36
+ self,
37
+ method: str,
38
+ route: str,
39
+ payload: Mapping[str, Any] | list[Any] | None = None,
40
+ *,
41
+ token: str | None = None,
42
+ ) -> Any:
43
+ url = urljoin(self.base_url.rstrip("/") + "/", route.lstrip("/"))
44
+ headers = {"Accept": "application/json"}
45
+ auth_token = token or self.token
46
+ if auth_token:
47
+ headers["Authorization"] = f"Bearer {auth_token}"
48
+ body = None
49
+ if payload is not None:
50
+ headers["Content-Type"] = "application/json"
51
+ body = json.dumps(payload).encode("utf-8")
52
+ request = Request(url, data=body, headers=headers, method=method.upper())
53
+ try:
54
+ with urlopen(request, timeout=self.timeout) as response:
55
+ raw = response.read()
56
+ if not raw:
57
+ return None
58
+ return json.loads(raw.decode("utf-8"))
59
+ except HTTPError as error:
60
+ raw = error.read().decode("utf-8", errors="replace")
61
+ try:
62
+ payload_data = json.loads(raw) if raw else None
63
+ except json.JSONDecodeError:
64
+ payload_data = raw
65
+ raise ApiError(error.code, error.reason, payload_data) from error
66
+ except URLError as error:
67
+ raise ApiError(0, str(error.reason)) from error
68
+
69
+ def health(self) -> Any:
70
+ """Return the gateway health response."""
71
+ return self._request("GET", "/health")
72
+
73
+ def shop(self, path: str = "", *, method: str = "GET", payload: Any = None) -> Any:
74
+ """Call a path proxied to the Shop API."""
75
+ return self._request(method, f"/shop/{path.lstrip('/')}", payload)
76
+
77
+ def cart(self, path: str = "", *, method: str = "GET", payload: Any = None) -> Any:
78
+ """Call a path proxied to the Cart API."""
79
+ return self._request(method, f"/cart/{path.lstrip('/')}", payload)
80
+
81
+ def purchase(self, path: str = "", *, method: str = "GET", payload: Any = None) -> Any:
82
+ """Call a path proxied to the Go Purchase service."""
83
+ return self._request(method, f"/purchase/{path.lstrip('/')}", payload)
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.5
2
+ Name: mycommerce-platform
3
+ Version: 0.1.0
4
+ Summary: Small, dependency-free Python client for the MyCommerce API gateway
5
+ Project-URL: Homepage, https://github.com/bayzed123/mycommerce
6
+ Project-URL: Repository, https://github.com/bayzed123/mycommerce
7
+ Project-URL: Issues, https://github.com/bayzed123/mycommerce/issues
8
+ Author: MyCommerce Contributors
9
+ License: MIT
10
+ Keywords: api,cart,ecommerce,mycommerce,payments,shop
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+
25
+ # mycommerce-platform
26
+
27
+ `mycommerce-platform` is the small, dependency-free Python client for the MyCommerce Cloudflare Worker gateway. It gives Python applications one stable base URL while the gateway routes requests to the Shop API, Cart API, and Go Purchase service.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install mycommerce-platform
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ```python
38
+ from mycommerce import MyCommerceClient
39
+
40
+ client = MyCommerceClient(
41
+ "https://mycommerce-api-gateway.<your-subdomain>.workers.dev",
42
+ token="optional-jwt-token",
43
+ )
44
+
45
+ print(client.health())
46
+ products = client.shop("api/v1/shop/")
47
+ cart = client.cart("cart/v1/")
48
+ payment = client.purchase("create", method="POST", payload={"sessionId": "session-123"})
49
+ ```
50
+
51
+ The package only uses Python's standard library. It does not contain Stripe, database, Django, or Cloudflare credentials. Authentication is supplied through the optional bearer token and service authorization remains a gateway/backend responsibility.
52
+
53
+ ## Development
54
+
55
+ ```bash
56
+ cd packages/mycommerce-platform
57
+ python -m venv .venv
58
+ . .venv/bin/activate
59
+ python -m pip install -U pip pytest
60
+ pytest
61
+ python -m build
62
+ ```
63
+
64
+ The package is published from GitHub Actions when a `mycommerce-platform-v*` tag is pushed. Configure a PyPI Trusted Publisher for this GitHub repository before creating the first release.
@@ -0,0 +1,5 @@
1
+ mycommerce/__init__.py,sha256=bhuIR99wgHcDF3xXCKC_gxAT4oUQSTzrSaiudaUyeeE,168
2
+ mycommerce/client.py,sha256=IFup92g9tI4RSpmACNH2OXHWVZCmm5ih9cI_o3gniAY,3196
3
+ mycommerce_platform-0.1.0.dist-info/METADATA,sha256=adjHxF7FQ2_cpGX3U9jcT8qnnqPKUQwX2weBKGLXqA4,2334
4
+ mycommerce_platform-0.1.0.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
5
+ mycommerce_platform-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.32.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any