carrier-python 0.1.30__tar.gz → 0.1.31__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.
Files changed (31) hide show
  1. {carrier_python-0.1.30 → carrier_python-0.1.31}/PKG-INFO +1 -1
  2. {carrier_python-0.1.30 → carrier_python-0.1.31}/pyproject.toml +1 -1
  3. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/__init__.py +22 -0
  4. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/client.py +16 -2
  5. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/resources.py +126 -0
  6. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/version.py +1 -1
  7. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier_python.egg-info/PKG-INFO +1 -1
  8. {carrier_python-0.1.30 → carrier_python-0.1.31}/tests/test_client.py +113 -0
  9. {carrier_python-0.1.30 → carrier_python-0.1.31}/tests/test_surface.py +1 -1
  10. {carrier_python-0.1.30 → carrier_python-0.1.31}/README.md +0 -0
  11. {carrier_python-0.1.30 → carrier_python-0.1.31}/setup.cfg +0 -0
  12. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/adapters.py +0 -0
  13. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/catalog.py +0 -0
  14. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/cli.py +0 -0
  15. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/data/cli.json +0 -0
  16. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/data/operations.json +0 -0
  17. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/errors.py +0 -0
  18. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/http.py +0 -0
  19. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/idempotency.py +0 -0
  20. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/mcp.py +0 -0
  21. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/models.py +0 -0
  22. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/operation_ids.py +0 -0
  23. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/operations.py +0 -0
  24. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/py.typed +0 -0
  25. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/records.py +0 -0
  26. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier/signature.py +0 -0
  27. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier_python.egg-info/SOURCES.txt +0 -0
  28. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier_python.egg-info/dependency_links.txt +0 -0
  29. {carrier_python-0.1.30 → carrier_python-0.1.31}/src/carrier_python.egg-info/top_level.txt +0 -0
  30. {carrier_python-0.1.30 → carrier_python-0.1.31}/tests/test_issuance.py +0 -0
  31. {carrier_python-0.1.30 → carrier_python-0.1.31}/tests/test_signature.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: carrier-python
3
- Version: 0.1.30
3
+ Version: 0.1.31
4
4
  Summary: Python client for the Carrier API, MCP server, and CLI.
5
5
  Author: Lifecycle Innovations Limited
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "carrier-python"
7
- version = "0.1.30"
7
+ version = "0.1.31"
8
8
  description = "Python client for the Carrier API, MCP server, and CLI."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -21,6 +21,18 @@ from carrier.records import (
21
21
  WebhookEndpoint,
22
22
  WebhookEndpointCreated,
23
23
  )
24
+ from carrier.resources import (
25
+ ESIMsResource,
26
+ Events,
27
+ EventsResource,
28
+ Intents,
29
+ Plans,
30
+ Products,
31
+ SandboxResource,
32
+ SubscribersResource,
33
+ UsageRecords,
34
+ WebhookEndpoints,
35
+ )
24
36
  from carrier.signature import verify_webhook_signature
25
37
  from carrier.version import __version__
26
38
 
@@ -30,8 +42,18 @@ __all__ = [
30
42
  "CarrierError",
31
43
  "Cli",
32
44
  "CliResult",
45
+ "ESIMsResource",
46
+ "Events",
47
+ "EventsResource",
48
+ "Intents",
33
49
  "Mcp",
34
50
  "OperationId",
51
+ "Plans",
52
+ "Products",
53
+ "SandboxResource",
54
+ "SubscribersResource",
55
+ "UsageRecords",
56
+ "WebhookEndpoints",
35
57
  "ConnectivityEsim",
36
58
  "ConnectivityEvent",
37
59
  "ConnectivityIntent",
@@ -6,7 +6,18 @@ from carrier.errors import CarrierError
6
6
  from carrier.http import DEFAULT_BASE_URL, Http, Transport, urllib_transport
7
7
  from carrier.operation_ids import OperationId
8
8
  from carrier.operations import call_operation
9
- from carrier.resources import Events, Intents, Plans, Products, UsageRecords, WebhookEndpoints
9
+ from carrier.resources import (
10
+ ESIMsResource,
11
+ Events,
12
+ EventsResource,
13
+ Intents,
14
+ Plans,
15
+ Products,
16
+ SandboxResource,
17
+ SubscribersResource,
18
+ UsageRecords,
19
+ WebhookEndpoints,
20
+ )
10
21
 
11
22
 
12
23
  class Carrier:
@@ -38,8 +49,11 @@ class Carrier:
38
49
  self.products = Products(http)
39
50
  self.plans = Plans(http)
40
51
  self.webhook_endpoints = WebhookEndpoints(http)
41
- self.events = Events(http)
52
+ self.events = EventsResource(http)
42
53
  self.usage_records = UsageRecords(http)
54
+ self.subscribers = SubscribersResource(http)
55
+ self.esims = ESIMsResource(http)
56
+ self.sandbox = SandboxResource(http)
43
57
 
44
58
  def call(
45
59
  self,
@@ -172,6 +172,132 @@ class Events:
172
172
  return ConnectivityEvent.from_dict(_as_object(self._http.request("POST", path)))
173
173
 
174
174
 
175
+ class EventsResource(Events):
176
+ """Connectivity events for this account, with event simulation."""
177
+
178
+ def simulate(
179
+ self,
180
+ event_type: str,
181
+ iccid: str,
182
+ payload: Mapping[str, Any] | None = None,
183
+ ) -> Any:
184
+ """POST /v1/connectivity/sandbox/simulate-event."""
185
+ body: dict[str, Any] = {
186
+ "type": event_type,
187
+ "iccid": iccid,
188
+ }
189
+ if payload is not None:
190
+ data = dict(payload)
191
+ if "carrier_id" in data:
192
+ body["carrier_id"] = data.pop("carrier_id")
193
+ body["data"] = data
194
+ res = self._http.request("POST", "/v1/connectivity/sandbox/simulate-event", body=body)
195
+ if isinstance(res, dict) and res.get("object") == "connectivity.event":
196
+ return ConnectivityEvent.from_dict(res)
197
+ return res
198
+
199
+
200
+ class SubscribersResource:
201
+ """Subscribers and SIM fleet management."""
202
+
203
+ def __init__(self, http: Http) -> None:
204
+ self._http = http
205
+
206
+ def list(self, page: int | None = None, limit: int | None = None, **kwargs: Any) -> Any:
207
+ """GET /v1/subscribers."""
208
+ query: dict[str, str] = {}
209
+ if page is not None:
210
+ query["page"] = str(page)
211
+ if limit is not None:
212
+ query["limit"] = str(limit)
213
+ for key, value in kwargs.items():
214
+ if value is not None:
215
+ query[key] = str(value)
216
+ return self._http.request("GET", "/v1/subscribers", query=query or None)
217
+
218
+ def get(self, id: str) -> Any:
219
+ """GET /v1/subscribers/:id."""
220
+ path = f"/v1/subscribers/{require_id(id, 'subscriber')}"
221
+ return self._http.request("GET", path)
222
+
223
+
224
+ class ESIMsResource:
225
+ """eSIM profile management."""
226
+
227
+ def __init__(self, http: Http) -> None:
228
+ self._http = http
229
+
230
+ def list(self, limit: int | None = None) -> Any:
231
+ """GET /v1/connectivity/intents."""
232
+ query: dict[str, str] = {}
233
+ if limit is not None:
234
+ if isinstance(limit, bool) or not isinstance(limit, int) or limit < 1 or limit > 100:
235
+ raise CarrierError(400, "invalid_limit", "limit must be an integer from 1 to 100.")
236
+ query["limit"] = str(limit)
237
+ payload = self._http.request("GET", "/v1/connectivity/intents", query=query or None)
238
+ try:
239
+ return parse_list(payload, ConnectivityIntent.from_dict)
240
+ except Exception:
241
+ return payload
242
+
243
+ def get(self, iccid: str) -> Any:
244
+ """GET /v1/connectivity/intents/:iccid."""
245
+ path = f"/v1/connectivity/intents/{require_id(iccid, 'esim')}"
246
+ payload = self._http.request("GET", path)
247
+ if isinstance(payload, dict) and payload.get("object") == "connectivity.intent":
248
+ return ConnectivityIntent.from_dict(payload)
249
+ return payload
250
+
251
+
252
+ class SandboxResource:
253
+ """Sandbox simulation environment and test network carriers."""
254
+
255
+ def __init__(self, http: Http) -> None:
256
+ self._http = http
257
+
258
+ def list_carriers(self) -> Any:
259
+ """GET /v1/connectivity/sandbox/carriers."""
260
+ return self._http.request("GET", "/v1/connectivity/sandbox/carriers")
261
+
262
+ def simulate_event(
263
+ self,
264
+ event_type: str,
265
+ iccid: str,
266
+ payload: Mapping[str, Any] | None = None,
267
+ ) -> Any:
268
+ """POST /v1/connectivity/sandbox/simulate-event."""
269
+ body: dict[str, Any] = {
270
+ "type": event_type,
271
+ "iccid": iccid,
272
+ }
273
+ if payload is not None:
274
+ data = dict(payload)
275
+ if "carrier_id" in data:
276
+ body["carrier_id"] = data.pop("carrier_id")
277
+ body["data"] = data
278
+ res = self._http.request("POST", "/v1/connectivity/sandbox/simulate-event", body=body)
279
+ if isinstance(res, dict) and res.get("object") == "connectivity.event":
280
+ return ConnectivityEvent.from_dict(res)
281
+ return res
282
+
283
+ def simulate_data_session(
284
+ self,
285
+ iccid: str,
286
+ bytes_used: int,
287
+ duration_seconds: int = 60,
288
+ ) -> Any:
289
+ """Simulate a data usage session on a test eSIM."""
290
+ return self.simulate_event(
291
+ "usage.data_recorded",
292
+ iccid,
293
+ payload={
294
+ "bytes_used": bytes_used,
295
+ "bytes_downlink": bytes_used,
296
+ "duration_seconds": duration_seconds,
297
+ },
298
+ )
299
+
300
+
175
301
  class UsageRecords:
176
302
  """Usage lines on a test intent. Live usage is metered by the network."""
177
303
 
@@ -1,3 +1,3 @@
1
1
  """Package version. Kept beside the HTTP client so the user agent stays in sync."""
2
2
 
3
- __version__ = "0.1.30"
3
+ __version__ = "0.1.31"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: carrier-python
3
- Version: 0.1.30
3
+ Version: 0.1.31
4
4
  Summary: Python client for the Carrier API, MCP server, and CLI.
5
5
  Author: Lifecycle Innovations Limited
6
6
  License: MIT
@@ -172,6 +172,119 @@ class ClientTest(unittest.TestCase):
172
172
  server.server_close()
173
173
  thread.join(timeout=2)
174
174
 
175
+ def test_subscribers_resource_list_and_get(self) -> None:
176
+ sub_data = {"data": [{"iccid": "8900000000000000001", "name": "Test User"}], "total": 1}
177
+ capture = Capture(200, sub_data)
178
+ carrier = Carrier("ak_test", base_url="https://api.test", transport=capture)
179
+
180
+ result = carrier.subscribers.list(page=2, limit=10)
181
+ self.assertEqual(result, sub_data)
182
+ self.assertEqual(capture.calls[0].method, "GET")
183
+ self.assertIn("/v1/subscribers", capture.calls[0].url)
184
+ self.assertIn("page=2", capture.calls[0].url)
185
+ self.assertIn("limit=10", capture.calls[0].url)
186
+
187
+ capture_get = Capture(200, {"data": {"iccid": "8900000000000000001", "name": "Test User"}})
188
+ carrier_get = Carrier("ak_test", base_url="https://api.test", transport=capture_get)
189
+ single = carrier_get.subscribers.get("8900000000000000001")
190
+ self.assertEqual(single["data"]["iccid"], "8900000000000000001")
191
+ self.assertEqual(capture_get.calls[0].url, "https://api.test/v1/subscribers/8900000000000000001")
192
+
193
+ with self.assertRaises(CarrierError) as raised:
194
+ carrier.subscribers.get("../bad")
195
+ self.assertEqual(raised.exception.code, "invalid_id")
196
+
197
+ def test_esims_resource_list_and_get(self) -> None:
198
+ capture = Capture(200, {"object": "list", "data": [INTENT]})
199
+ carrier = Carrier("ak_test", base_url="https://api.test", transport=capture)
200
+
201
+ esims = carrier.esims.list(limit=5)
202
+ self.assertEqual(len(esims), 1)
203
+ self.assertEqual(esims[0].id, INTENT["id"])
204
+ self.assertIn("limit=5", capture.calls[0].url)
205
+ self.assertIn("/v1/connectivity/intents", capture.calls[0].url)
206
+
207
+ capture_get = Capture(200, INTENT)
208
+ carrier_get = Carrier("ak_test", base_url="https://api.test", transport=capture_get)
209
+ single = carrier_get.esims.get(INTENT["id"])
210
+ self.assertEqual(single.id, INTENT["id"])
211
+ self.assertEqual(capture_get.calls[0].url, f"https://api.test/v1/connectivity/intents/{INTENT['id']}")
212
+
213
+ with self.assertRaises(CarrierError) as raised:
214
+ carrier.esims.get("../bad")
215
+ self.assertEqual(raised.exception.code, "invalid_id")
216
+
217
+ def test_sandbox_resource_carriers_and_simulate(self) -> None:
218
+ carriers_data = {
219
+ "object": "list",
220
+ "data": [
221
+ {"id": "carrier_alphatel", "name": "AlphaTel US"},
222
+ {"id": "carrier_apex", "name": "Apex Mobile Europe"},
223
+ ],
224
+ }
225
+ capture = Capture(200, carriers_data)
226
+ carrier = Carrier("ak_test", base_url="https://api.test", transport=capture)
227
+
228
+ carriers = carrier.sandbox.list_carriers()
229
+ self.assertEqual(carriers["object"], "list")
230
+ self.assertEqual(len(carriers["data"]), 2)
231
+ self.assertEqual(capture.calls[0].url, "https://api.test/v1/connectivity/sandbox/carriers")
232
+
233
+ event_data = {
234
+ "id": "evt_0123456789abcdef0123456789abcdef",
235
+ "object": "connectivity.event",
236
+ "type": "network.attached",
237
+ "livemode": False,
238
+ "created": 1000,
239
+ "data": {"iccid": "8900000000000000001", "simulated": True},
240
+ }
241
+ capture_evt = Capture(201, event_data)
242
+ carrier_evt = Carrier("ak_test", base_url="https://api.test", transport=capture_evt)
243
+
244
+ event = carrier_evt.sandbox.simulate_event(
245
+ "network.attached",
246
+ "8900000000000000001",
247
+ payload={"carrier_id": "carrier_alphatel", "foo": "bar"},
248
+ )
249
+ self.assertEqual(event.id, event_data["id"])
250
+ self.assertEqual(event.type, "network.attached")
251
+ sent_body = json.loads(capture_evt.calls[0].body or b"")
252
+ self.assertEqual(sent_body["type"], "network.attached")
253
+ self.assertEqual(sent_body["iccid"], "8900000000000000001")
254
+ self.assertEqual(sent_body["carrier_id"], "carrier_alphatel")
255
+ self.assertEqual(sent_body["data"], {"foo": "bar"})
256
+
257
+ # test simulate_data_session
258
+ capture_session = Capture(201, event_data)
259
+ carrier_session = Carrier("ak_test", base_url="https://api.test", transport=capture_session)
260
+ carrier_session.sandbox.simulate_data_session("8900000000000000001", bytes_used=5242880, duration_seconds=120)
261
+ session_body = json.loads(capture_session.calls[0].body or b"")
262
+ self.assertEqual(session_body["type"], "usage.data_recorded")
263
+ self.assertEqual(session_body["iccid"], "8900000000000000001")
264
+ self.assertEqual(session_body["data"]["bytes_used"], 5242880)
265
+ self.assertEqual(session_body["data"]["duration_seconds"], 120)
266
+
267
+ def test_events_resource_simulate(self) -> None:
268
+ event_data = {
269
+ "id": "evt_0123456789abcdef0123456789abcdef",
270
+ "object": "connectivity.event",
271
+ "type": "usage.threshold_reached",
272
+ "livemode": False,
273
+ "created": 1000,
274
+ "data": {"threshold_percent": 80},
275
+ }
276
+ capture = Capture(201, event_data)
277
+ carrier = Carrier("ak_test", base_url="https://api.test", transport=capture)
278
+
279
+ event = carrier.events.simulate("usage.threshold_reached", "8900000000000000001", payload={"threshold_percent": 80})
280
+ self.assertEqual(event.id, event_data["id"])
281
+ self.assertEqual(event.type, "usage.threshold_reached")
282
+ sent = json.loads(capture.calls[0].body or b"")
283
+ self.assertEqual(sent["type"], "usage.threshold_reached")
284
+ self.assertEqual(sent["iccid"], "8900000000000000001")
285
+ self.assertEqual(sent["data"]["threshold_percent"], 80)
286
+ self.assertEqual(capture.calls[0].url, "https://api.test/v1/connectivity/sandbox/simulate-event")
287
+
175
288
 
176
289
  if __name__ == "__main__":
177
290
  unittest.main()
@@ -201,7 +201,7 @@ class SurfaceTest(unittest.TestCase):
201
201
  package = Path(__file__).resolve().parents[1]
202
202
  with (package / "pyproject.toml").open("rb") as handle:
203
203
  version = tomllib.load(handle)["project"]["version"]
204
- self.assertEqual(version, "0.1.30")
204
+ self.assertEqual(version, "0.1.31")
205
205
  self.assertEqual(version, __version__)
206
206
  with (package / "uv.lock").open("rb") as handle:
207
207
  lock = tomllib.load(handle)