lynkora-sdk-python 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,4 @@
1
+ from .client import LynkoraClient
2
+ from .errors import LynkoraApiError
3
+
4
+ __all__ = ["LynkoraClient", "LynkoraApiError"]
lynkora_sdk/client.py ADDED
@@ -0,0 +1,78 @@
1
+ import json
2
+ from urllib.error import HTTPError
3
+ from urllib.request import Request, urlopen
4
+
5
+ from .errors import LynkoraApiError
6
+
7
+
8
+ class LynkoraClient:
9
+ def __init__(self, api_key: str, base_url: str) -> None:
10
+ self._api_key = api_key
11
+ self._base_url = base_url
12
+
13
+ def register_subscriber(
14
+ self,
15
+ suite_id: str,
16
+ name: str,
17
+ email: str,
18
+ document: str | None = None,
19
+ metadata: dict | None = None,
20
+ ) -> dict:
21
+ body = {"name": name, "email": email}
22
+ if document is not None:
23
+ body["document"] = document
24
+ if metadata is not None:
25
+ body["metadata"] = metadata
26
+ return self._request(
27
+ "POST", f"/v1/suites/{suite_id}/subscribers/register", body
28
+ )
29
+
30
+ def consume_action(
31
+ self,
32
+ subscriber_id: str,
33
+ action_slug: str,
34
+ quantity: int | None = None,
35
+ metadata: dict | None = None,
36
+ ) -> dict:
37
+ body = {"subscriberId": subscriber_id, "actionSlug": action_slug}
38
+ if quantity is not None:
39
+ body["quantity"] = quantity
40
+ if metadata is not None:
41
+ body["metadata"] = metadata
42
+ return self._request("POST", "/v1/actions/consume", body)
43
+
44
+ def confirm_consumption(self, reservation_id: str) -> dict:
45
+ return self._request("POST", f"/v1/actions/confirm/{reservation_id}")
46
+
47
+ def cancel_consumption(self, reservation_id: str) -> None:
48
+ return self._request("POST", f"/v1/actions/cancel/{reservation_id}")
49
+
50
+ def _request(self, method: str, path: str, body: dict | None = None) -> object:
51
+ data = json.dumps(body).encode("utf-8") if body is not None else None
52
+ req = Request(
53
+ f"{self._base_url}{path}",
54
+ data=data,
55
+ method=method,
56
+ headers={
57
+ "X-Api-Key": self._api_key,
58
+ "Content-Type": "application/json",
59
+ },
60
+ )
61
+
62
+ try:
63
+ with urlopen(req) as response:
64
+ if response.status == 204:
65
+ return None
66
+ return json.loads(response.read())
67
+ except HTTPError as e:
68
+ raw = e.read()
69
+ try:
70
+ error_body = json.loads(raw) if raw else None
71
+ except ValueError:
72
+ error_body = None
73
+ message = (
74
+ error_body.get("message")
75
+ if isinstance(error_body, dict) and error_body.get("message")
76
+ else e.reason
77
+ )
78
+ raise LynkoraApiError(e.code, message, error_body) from e
lynkora_sdk/errors.py ADDED
@@ -0,0 +1,5 @@
1
+ class LynkoraApiError(Exception):
2
+ def __init__(self, status_code: int, message: str, body: object) -> None:
3
+ super().__init__(message)
4
+ self.status_code = status_code
5
+ self.body = body
@@ -0,0 +1,72 @@
1
+ Metadata-Version: 2.4
2
+ Name: lynkora-sdk-python
3
+ Version: 0.1.0
4
+ Summary: SDK Python para integração com a API de Actions/Subscribers do Lynkora Admin Service.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://docs.lynkora.dev/docs/para-desenvolvedores/sdks
7
+ Project-URL: Repository, https://github.com/natanaeldeveloper/lynkora-api
8
+ Project-URL: Issues, https://github.com/natanaeldeveloper/lynkora-api/issues
9
+ Keywords: lynkora,billing,usage-based-billing,metering,sdk
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=8.0; extra == "dev"
15
+ Requires-Dist: build>=1.0; extra == "dev"
16
+ Requires-Dist: twine>=5.0; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # lynkora-sdk-python
20
+
21
+ SDK Python pra integrar com a API pública do Lynkora — registrar assinantes e
22
+ controlar consumo (reservar, confirmar, cancelar). Zero dependências de
23
+ runtime (usa `urllib.request` da biblioteca padrão), cliente síncrono.
24
+
25
+ Documentação completa dos endpoints: [docs.lynkora.dev/docs/para-desenvolvedores/sdks](https://docs.lynkora.dev/docs/para-desenvolvedores/sdks).
26
+
27
+ ## Instalação
28
+
29
+ ```bash
30
+ pip install lynkora-sdk-python
31
+ ```
32
+
33
+ ## Uso
34
+
35
+ ```python
36
+ import os
37
+ from lynkora_sdk import LynkoraClient
38
+
39
+ lynkora = LynkoraClient(
40
+ api_key=os.environ["LYNKORA_API_KEY"],
41
+ base_url="https://api.lynkora.dev",
42
+ )
43
+
44
+ result = lynkora.consume_action(
45
+ subscriber_id="sub_123",
46
+ action_slug="generate-report",
47
+ )
48
+
49
+ lynkora.confirm_consumption(result["reservationId"])
50
+ ```
51
+
52
+ Erros da API chegam como `LynkoraApiError`, com `status_code`, a mensagem (via
53
+ `str(err)`) e o corpo original da resposta em `body`:
54
+
55
+ ```python
56
+ from lynkora_sdk import LynkoraApiError
57
+
58
+ try:
59
+ lynkora.consume_action(subscriber_id="sub_123", action_slug="generate-report")
60
+ except LynkoraApiError as err:
61
+ print(err.status_code, str(err), err.body)
62
+ ```
63
+
64
+ ## Escopo
65
+
66
+ Só os 4 endpoints autenticados por `X-Api-Key`: `consume_action`,
67
+ `confirm_consumption`, `cancel_consumption` e `register_subscriber`. Nada de
68
+ painel administrativo nem cobrança — isso é feito direto pela API.
69
+
70
+ ## Licença
71
+
72
+ MIT
@@ -0,0 +1,8 @@
1
+ lynkora_sdk/__init__.py,sha256=l3OB5aTQnhnIVUxCo90glO-75fe3RiipxPUZ2Ys8qHI,118
2
+ lynkora_sdk/client.py,sha256=N97Yea13LvD35DXucLYX1rYAlfrmRntOz4g-CKpTlUw,2592
3
+ lynkora_sdk/errors.py,sha256=2Etnrp0dykVeXP8bc1caD0-41xVj2w1a-RO_jvFZKR4,210
4
+ lynkora_sdk_python-0.1.0.dist-info/licenses/LICENSE,sha256=F6L4fbhXv8SquSXEKIOJ6vjHuFi-ftTeH9HDyYKkIGw,1064
5
+ lynkora_sdk_python-0.1.0.dist-info/METADATA,sha256=_pgG8VwZC5a3LDbr_EvpxLjeQ0qz1c_w_DZTwrrhE0Y,2122
6
+ lynkora_sdk_python-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
7
+ lynkora_sdk_python-0.1.0.dist-info/top_level.txt,sha256=QN5jLv9Y37lVO_GCfayaHC1TdcEZ9Q6SnWepbU2507s,12
8
+ lynkora_sdk_python-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lynkora
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
+ lynkora_sdk