python3-commons 0.6.2__py3-none-any.whl → 0.6.4__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,44 @@
1
+ from contextlib import asynccontextmanager
2
+ from datetime import datetime, UTC
3
+ from typing import Literal, Mapping
4
+ from urllib.parse import urlencode
5
+
6
+ import aiohttp
7
+ from pydantic import HttpUrl
8
+
9
+ from python3_commons import audit
10
+ from python3_commons.conf import s3_settings
11
+ from python3_commons.helpers import request_to_curl
12
+
13
+
14
+ @asynccontextmanager
15
+ async def request(
16
+ base_url: HttpUrl,
17
+ uri: str,
18
+ params: Mapping | None = None,
19
+ method: Literal['get', 'post', 'patch', 'put', 'delete'] = 'get',
20
+ audit_name: str | None = None,
21
+ ):
22
+ now = datetime.now(tz=UTC)
23
+ date_path = now.strftime('%Y/%m/%d')
24
+ timestamp = now.strftime('%H%M%S_%f')
25
+ uri_path = uri[:-1] if uri.endswith('/') else uri
26
+ uri_path = uri_path[1:] if uri_path.startswith('/') else uri_path
27
+ url = f'{base_url}{uri}'
28
+
29
+ if params:
30
+ url_with_params = f'{url}?{urlencode(params)}'
31
+
32
+ if audit_name:
33
+ curl_request = request_to_curl(url_with_params, method, {}, None)
34
+ await audit.write_audit_data(
35
+ s3_settings,
36
+ f'{date_path}/{audit_name}/{uri_path}/{method}_{timestamp}_request.txt',
37
+ curl_request.encode('utf-8')
38
+ )
39
+
40
+ async with aiohttp.ClientSession() as client:
41
+ client_method = getattr(client, method)
42
+
43
+ async with client_method(url, params=params) as response:
44
+ yield response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: python3-commons
3
- Version: 0.6.2
3
+ Version: 0.6.4
4
4
  Summary: Re-usable Python3 code
5
5
  Author-email: Oleg Korsak <kamikaze.is.waiting.you@gmail.com>
6
6
  License: gpl-3
@@ -12,12 +12,13 @@ Requires-Python: >=3.13
12
12
  Description-Content-Type: text/x-rst
13
13
  License-File: LICENSE
14
14
  License-File: AUTHORS.rst
15
+ Requires-Dist: aiohttp[speedups]==3.11.11
15
16
  Requires-Dist: asyncpg==0.30.0
16
17
  Requires-Dist: lxml==5.3.0
17
- Requires-Dist: minio==7.2.14
18
+ Requires-Dist: minio==7.2.15
18
19
  Requires-Dist: msgpack==1.1.0
19
20
  Requires-Dist: msgspec==0.19.0
20
- Requires-Dist: pydantic[email]==2.10.5
21
+ Requires-Dist: pydantic[email]==2.10.6
21
22
  Requires-Dist: pydantic-settings==2.7.1
22
23
  Requires-Dist: zeep==4.3.1
23
24
  Provides-Extra: testing
@@ -1,4 +1,5 @@
1
1
  python3_commons/__init__.py,sha256=0KgaYU46H_IMKn-BuasoRN3C4Hi45KlkHHoPbU9cwiA,189
2
+ python3_commons/api_client.py,sha256=7DXXviUdinw80aTTn11Eh-goGmVdnAcaZsI27qVb2nQ,1420
2
3
  python3_commons/audit.py,sha256=fokdHYthtZWc1HQA2lZ74mQVkAh57oFzH-N97RS3tSc,5865
3
4
  python3_commons/conf.py,sha256=qm2a2yWOhfawicBPjWnUett8TrsMtoyQXDxEJ_N-v-Y,637
4
5
  python3_commons/db.py,sha256=qhaDIdzBWgFyeP_XPKfHZlYVlwS2bpBPYMv84yV6820,738
@@ -12,9 +13,9 @@ python3_commons/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
12
13
  python3_commons/serializers/json.py,sha256=P288wWz9ic38QWEMrpp_uwKPYkQiOgvE1cI4WZn6ZCg,808
13
14
  python3_commons/serializers/msgpack.py,sha256=tzIGGyDL3UpZnnouCtnxuYDx6InKM_C3PP1N4PN8wd4,1269
14
15
  python3_commons/serializers/msgspec.py,sha256=EknuMpxi_kU25Iv_m10E9rk8b31AkjVumuzyjp7WgrU,1699
15
- python3_commons-0.6.2.dist-info/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
16
- python3_commons-0.6.2.dist-info/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
17
- python3_commons-0.6.2.dist-info/METADATA,sha256=vqvzAeLgnTd7McQSJh2WVSGJ4Lbk4T3EmsuNzAX5BE8,943
18
- python3_commons-0.6.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
19
- python3_commons-0.6.2.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
20
- python3_commons-0.6.2.dist-info/RECORD,,
16
+ python3_commons-0.6.4.dist-info/AUTHORS.rst,sha256=3R9JnfjfjH5RoPWOeqKFJgxVShSSfzQPIrEr1nxIo9Q,90
17
+ python3_commons-0.6.4.dist-info/LICENSE,sha256=xxILuojHm4fKQOrMHPSslbyy6WuKAN2RiG74HbrYfzM,34575
18
+ python3_commons-0.6.4.dist-info/METADATA,sha256=ovwYcrhEzhLv-GOr0RdEmA3upp_WhLnyx5enJ0K6D5Q,985
19
+ python3_commons-0.6.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
20
+ python3_commons-0.6.4.dist-info/top_level.txt,sha256=lJI6sCBf68eUHzupCnn2dzG10lH3jJKTWM_hrN1cQ7M,16
21
+ python3_commons-0.6.4.dist-info/RECORD,,