aio-http-waiter 0.0.1__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,3 @@
1
+ .venv
2
+ __pycache__
3
+ dist
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fabio Antonio Astore
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,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: aio-http-waiter
3
+ Version: 0.0.1
4
+ Summary: Python HTTP Waiter
5
+ Author-email: Fabio Antonio Astore <astore.a.fabio@gmail.com>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.14
9
+ Requires-Dist: aiohttp-retry==2.9.1
10
+ Requires-Dist: aiohttp[speedups]==3.13.3
11
+ Description-Content-Type: text/markdown
12
+
13
+ # http-waiter
14
+ Python HTTP
@@ -0,0 +1,2 @@
1
+ # http-waiter
2
+ Python HTTP
@@ -0,0 +1,3 @@
1
+ from .client import Client
2
+
3
+ __all__ = ["Client"]
@@ -0,0 +1,87 @@
1
+ import asyncio
2
+ from typing import Any, Self
3
+
4
+ import aiohttp
5
+ import aiohttp_retry
6
+
7
+
8
+ RETRY_STATUS_CODE = {408, 429, 503, 504}
9
+
10
+
11
+ class Client:
12
+ def __init__(
13
+ self,
14
+ base_url: str | None = None,
15
+ attempts: int = 0,
16
+ statuses: set[int] = RETRY_STATUS_CODE,
17
+ ) -> None:
18
+ self.__session: aiohttp.ClientSession | None = None
19
+ self._base_url = base_url
20
+ self._retry_options = aiohttp_retry.ExponentialRetry(
21
+ attempts=attempts, statuses=statuses
22
+ )
23
+ self._retry_client: aiohttp_retry.RetryClient | None = None
24
+ self.__lock = asyncio.Lock()
25
+
26
+ @property
27
+ def base_url(self) -> str | None:
28
+ return self._base_url
29
+
30
+ async def __aenter__(self) -> Self:
31
+ await self._create_session()
32
+ return self
33
+
34
+ async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
35
+ await self.aclose()
36
+
37
+ async def aclose(self) -> None:
38
+ if self.__session is not None and not self.__session.closed:
39
+ await self.__session.close()
40
+ if self._retry_client is not None:
41
+ await self._retry_client.close()
42
+
43
+ async def _create_session(self) -> aiohttp.ClientSession:
44
+ async with self.__lock:
45
+ if self.__session is None or self.__session.closed:
46
+ self.__session = aiohttp.ClientSession(base_url=self._base_url)
47
+ return self.__session
48
+
49
+ async def _get_session(self) -> aiohttp.ClientSession:
50
+ if self.__session is not None and not self.__session.closed:
51
+ return self.__session
52
+ return await self._create_session()
53
+
54
+ async def _create_retry_client(self) -> aiohttp_retry.RetryClient:
55
+ async with self.__lock:
56
+ if self._retry_client is None:
57
+ session = await self._get_session()
58
+ self._retry_client = aiohttp_retry.RetryClient(
59
+ client_session=session, retry_options=self._retry_options
60
+ )
61
+ return self._retry_client
62
+
63
+ async def _get_retry_client(self) -> aiohttp_retry.RetryClient:
64
+ if self._retry_client is not None:
65
+ return self._retry_client
66
+ return await self._create_retry_client()
67
+
68
+ async def request(
69
+ self, method: str, url: str, **kwargs: Any
70
+ ) -> aiohttp.ClientResponse:
71
+ retry_client = await self._get_retry_client()
72
+ return await retry_client.request(method=method, url=url, **kwargs)
73
+
74
+ async def get(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
75
+ return await self.request(method="GET", url=url, **kwargs)
76
+
77
+ async def post(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
78
+ return await self.request(method="POST", url=url, **kwargs)
79
+
80
+ async def put(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
81
+ return await self.request(method="PUT", url=url, **kwargs)
82
+
83
+ async def patch(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
84
+ return await self.request(method="PATCH", url=url, **kwargs)
85
+
86
+ async def delete(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
87
+ return await self.request(method="DELETE", url=url, **kwargs)
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "aio-http-waiter"
7
+ version = "0.0.1"
8
+ description = "Python HTTP Waiter"
9
+ readme = "README.md"
10
+ requires-python = ">=3.14"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Fabio Antonio Astore", email = "astore.a.fabio@gmail.com" },
14
+ ]
15
+ dependencies = [
16
+ "aiohttp[speedups] == 3.13.3",
17
+ "aiohttp-retry == 2.9.1"
18
+ ]
19
+
20
+ [tool.hatch.build.targets.wheel]
21
+ packages = ["src/http_waiter"]
22
+
23
+ [tool.hatch.build.targets.sdist]
24
+ packages = ["src/http_waiter"]