procedere-mq-sdk 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,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: procedere-mq-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK para LiteMQ/ProcedereMQ
5
+ Project-URL: Homepage, https://github.com/jeffersontadeuleite/procedereMQ
6
+ Project-URL: Repository, https://github.com/jeffersontadeuleite/procedereMQ
7
+ Project-URL: Issues, https://github.com/jeffersontadeuleite/procedereMQ/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: requests>=2.31.0
18
+
19
+ # ProcedereMQ
20
+
21
+ Broker de filas leve com transporte HTTP/TCP e SDKs para Go e Python.
22
+
23
+ ## SDK Go
24
+
25
+ Import:
26
+
27
+ ```go
28
+ import "github.com/jeffersontadeuleite/procedereMQ/pkg/sdk"
29
+ ```
30
+
31
+ Exemplo:
32
+
33
+ ```go
34
+ client := sdk.NewClient("http://127.0.0.1:65090")
35
+ job, err := client.Dequeue(ctx, "emails")
36
+ if err != nil {
37
+ return err
38
+ }
39
+ _ = client.Ack(ctx, job.ID)
40
+ ```
41
+
42
+ ## SDK Python
43
+
44
+ Instalação:
45
+
46
+ ```bash
47
+ pip install procedere-mq-sdk
48
+ ```
49
+
50
+ Exemplo:
51
+
52
+ ```python
53
+ from python_sdk import LiteMQClient
54
+
55
+ client = LiteMQClient("http://127.0.0.1:65090")
56
+ job = client.dequeue("emails")
57
+ client.ack(job["id"])
58
+ ```
59
+
60
+ ## Publicação
61
+
62
+ ### Go SDK
63
+
64
+ ```bash
65
+ make publish-go-sdk VERSION=0.2.0
66
+ ```
67
+
68
+ ### Python SDK (PyPI)
69
+
70
+ ```bash
71
+ make check-python-sdk
72
+ make publish-python-sdk TWINE_REPOSITORY=pypi
73
+ ```
@@ -0,0 +1,55 @@
1
+ # ProcedereMQ
2
+
3
+ Broker de filas leve com transporte HTTP/TCP e SDKs para Go e Python.
4
+
5
+ ## SDK Go
6
+
7
+ Import:
8
+
9
+ ```go
10
+ import "github.com/jeffersontadeuleite/procedereMQ/pkg/sdk"
11
+ ```
12
+
13
+ Exemplo:
14
+
15
+ ```go
16
+ client := sdk.NewClient("http://127.0.0.1:65090")
17
+ job, err := client.Dequeue(ctx, "emails")
18
+ if err != nil {
19
+ return err
20
+ }
21
+ _ = client.Ack(ctx, job.ID)
22
+ ```
23
+
24
+ ## SDK Python
25
+
26
+ Instalação:
27
+
28
+ ```bash
29
+ pip install procedere-mq-sdk
30
+ ```
31
+
32
+ Exemplo:
33
+
34
+ ```python
35
+ from python_sdk import LiteMQClient
36
+
37
+ client = LiteMQClient("http://127.0.0.1:65090")
38
+ job = client.dequeue("emails")
39
+ client.ack(job["id"])
40
+ ```
41
+
42
+ ## Publicação
43
+
44
+ ### Go SDK
45
+
46
+ ```bash
47
+ make publish-go-sdk VERSION=0.2.0
48
+ ```
49
+
50
+ ### Python SDK (PyPI)
51
+
52
+ ```bash
53
+ make check-python-sdk
54
+ make publish-python-sdk TWINE_REPOSITORY=pypi
55
+ ```
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: procedere-mq-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK para LiteMQ/ProcedereMQ
5
+ Project-URL: Homepage, https://github.com/jeffersontadeuleite/procedereMQ
6
+ Project-URL: Repository, https://github.com/jeffersontadeuleite/procedereMQ
7
+ Project-URL: Issues, https://github.com/jeffersontadeuleite/procedereMQ/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Software Development :: Libraries
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: requests>=2.31.0
18
+
19
+ # ProcedereMQ
20
+
21
+ Broker de filas leve com transporte HTTP/TCP e SDKs para Go e Python.
22
+
23
+ ## SDK Go
24
+
25
+ Import:
26
+
27
+ ```go
28
+ import "github.com/jeffersontadeuleite/procedereMQ/pkg/sdk"
29
+ ```
30
+
31
+ Exemplo:
32
+
33
+ ```go
34
+ client := sdk.NewClient("http://127.0.0.1:65090")
35
+ job, err := client.Dequeue(ctx, "emails")
36
+ if err != nil {
37
+ return err
38
+ }
39
+ _ = client.Ack(ctx, job.ID)
40
+ ```
41
+
42
+ ## SDK Python
43
+
44
+ Instalação:
45
+
46
+ ```bash
47
+ pip install procedere-mq-sdk
48
+ ```
49
+
50
+ Exemplo:
51
+
52
+ ```python
53
+ from python_sdk import LiteMQClient
54
+
55
+ client = LiteMQClient("http://127.0.0.1:65090")
56
+ job = client.dequeue("emails")
57
+ client.ack(job["id"])
58
+ ```
59
+
60
+ ## Publicação
61
+
62
+ ### Go SDK
63
+
64
+ ```bash
65
+ make publish-go-sdk VERSION=0.2.0
66
+ ```
67
+
68
+ ### Python SDK (PyPI)
69
+
70
+ ```bash
71
+ make check-python-sdk
72
+ make publish-python-sdk TWINE_REPOSITORY=pypi
73
+ ```
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ procedere_mq_sdk.egg-info/PKG-INFO
4
+ procedere_mq_sdk.egg-info/SOURCES.txt
5
+ procedere_mq_sdk.egg-info/dependency_links.txt
6
+ procedere_mq_sdk.egg-info/requires.txt
7
+ procedere_mq_sdk.egg-info/top_level.txt
8
+ python_sdk/__init__.py
9
+ python_sdk/client.py
@@ -0,0 +1 @@
1
+ requests>=2.31.0
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "procedere-mq-sdk"
7
+ version = "0.1.0"
8
+ description = "Python SDK para LiteMQ/ProcedereMQ"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ dependencies = [
12
+ "requests>=2.31.0",
13
+ ]
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3 :: Only",
17
+ "Programming Language :: Python :: 3.9",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Intended Audience :: Developers",
21
+ "Topic :: Software Development :: Libraries",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/jeffersontadeuleite/procedereMQ"
26
+ Repository = "https://github.com/jeffersontadeuleite/procedereMQ"
27
+ Issues = "https://github.com/jeffersontadeuleite/procedereMQ/issues"
28
+
29
+ [tool.setuptools]
30
+ packages = ["python_sdk"]
@@ -0,0 +1,8 @@
1
+ from .client import LiteMQClient, LiteMQError, NotFoundError, QueueEmptyError
2
+
3
+ __all__ = [
4
+ "LiteMQClient",
5
+ "LiteMQError",
6
+ "NotFoundError",
7
+ "QueueEmptyError",
8
+ ]
@@ -0,0 +1,99 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import datetime, timezone
4
+ from typing import Any
5
+
6
+ import requests
7
+
8
+
9
+ class LiteMQError(Exception):
10
+ pass
11
+
12
+
13
+ class QueueEmptyError(LiteMQError):
14
+ pass
15
+
16
+
17
+ class NotFoundError(LiteMQError):
18
+ pass
19
+
20
+
21
+ class LiteMQClient:
22
+ def __init__(self, base_url: str, timeout: float = 10.0) -> None:
23
+ self.base_url = base_url.rstrip("/")
24
+ self.timeout = timeout
25
+ self.session = requests.Session()
26
+
27
+ def enqueue(
28
+ self,
29
+ queue: str,
30
+ payload: dict[str, Any] | list[Any] | str | int | float | bool | None = None,
31
+ *,
32
+ job_id: str | None = None,
33
+ max_retry: int | None = None,
34
+ run_at: datetime | None = None,
35
+ ) -> dict[str, Any]:
36
+ if not queue or not queue.strip():
37
+ raise ValueError("queue is required")
38
+ body: dict[str, Any] = {"queue": queue}
39
+ if payload is not None:
40
+ body["payload"] = payload
41
+ if job_id:
42
+ body["id"] = job_id
43
+ if max_retry is not None:
44
+ body["max_retry"] = max_retry
45
+ if run_at is not None:
46
+ body["run_at"] = self._format_datetime(run_at)
47
+ return self._request("POST", "/enqueue", json=body, expected_status=201)
48
+
49
+ def dequeue(self, queue: str) -> dict[str, Any]:
50
+ if not queue or not queue.strip():
51
+ raise ValueError("queue is required")
52
+ return self._request("GET", "/dequeue", params={"queue": queue}, expected_status=200)
53
+
54
+ def ack(self, job_id: str) -> dict[str, Any]:
55
+ if not job_id or not job_id.strip():
56
+ raise ValueError("job_id is required")
57
+ return self._request("POST", "/ack", json={"id": job_id}, expected_status=200)
58
+
59
+ def fail(self, job_id: str) -> dict[str, Any]:
60
+ if not job_id or not job_id.strip():
61
+ raise ValueError("job_id is required")
62
+ return self._request("POST", "/fail", json={"id": job_id}, expected_status=200)
63
+
64
+ def _request(self, method: str, path: str, expected_status: int, **kwargs: Any) -> dict[str, Any]:
65
+ url = f"{self.base_url}{path}"
66
+ response = self.session.request(method, url, timeout=self.timeout, **kwargs)
67
+
68
+ if response.status_code == 204:
69
+ raise QueueEmptyError("queue empty")
70
+ if response.status_code == 404:
71
+ raise NotFoundError(self._extract_error(response))
72
+ if response.status_code != expected_status:
73
+ raise LiteMQError(self._extract_error(response))
74
+
75
+ if not response.content:
76
+ return {}
77
+
78
+ data = response.json()
79
+ if isinstance(data, dict):
80
+ return data
81
+ return {"data": data}
82
+
83
+ @staticmethod
84
+ def _extract_error(response: requests.Response) -> str:
85
+ try:
86
+ payload = response.json()
87
+ except ValueError:
88
+ return response.text or response.reason
89
+ if isinstance(payload, dict):
90
+ message = payload.get("error")
91
+ if isinstance(message, str) and message.strip():
92
+ return message
93
+ return response.text or response.reason
94
+
95
+ @staticmethod
96
+ def _format_datetime(value: datetime) -> str:
97
+ if value.tzinfo is None:
98
+ value = value.replace(tzinfo=timezone.utc)
99
+ return value.astimezone(timezone.utc).isoformat().replace("+00:00", "Z")
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+