polars-api 0.1.4__py3-none-any.whl → 0.1.5__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- polars_api/api.py +30 -24
- {polars_api-0.1.4.dist-info → polars_api-0.1.5.dist-info}/METADATA +1 -1
- polars_api-0.1.5.dist-info/RECORD +9 -0
- polars_api-0.1.4.dist-info/RECORD +0 -9
- {polars_api-0.1.4.dist-info → polars_api-0.1.5.dist-info}/LICENSE +0 -0
- {polars_api-0.1.4.dist-info → polars_api-0.1.5.dist-info}/WHEEL +0 -0
- {polars_api-0.1.4.dist-info → polars_api-0.1.5.dist-info}/top_level.txt +0 -0
polars_api/api.py
CHANGED
@@ -15,77 +15,83 @@ class Api:
|
|
15
15
|
self._url = url
|
16
16
|
|
17
17
|
@staticmethod
|
18
|
-
def _get(url: str, params: Optional[dict[str, str]] = None) -> Optional[str]:
|
19
|
-
result = httpx.get(url, params=params)
|
18
|
+
def _get(url: str, params: Optional[dict[str, str]] = None, timeout: Optional[float] = None) -> Optional[str]:
|
19
|
+
result = httpx.get(url, params=params, timeout=timeout)
|
20
20
|
if check_status_code(result.status_code):
|
21
21
|
return result.text
|
22
22
|
else:
|
23
23
|
return None
|
24
24
|
|
25
25
|
@staticmethod
|
26
|
-
def _post(url: str, params: dict[str, str], body: str) -> Optional[str]:
|
27
|
-
result = httpx.post(url, params=params, json=body)
|
26
|
+
def _post(url: str, params: dict[str, str], body: str, timeout: float) -> Optional[str]:
|
27
|
+
result = httpx.post(url, params=params, json=body, timeout=timeout)
|
28
28
|
if check_status_code(result.status_code):
|
29
29
|
return result.text
|
30
30
|
else:
|
31
31
|
return None
|
32
32
|
|
33
33
|
@staticmethod
|
34
|
-
async def _aget_one(url: str, params: str) -> str:
|
34
|
+
async def _aget_one(url: str, params: str, timeout: float) -> str:
|
35
35
|
async with httpx.AsyncClient() as client:
|
36
|
-
r = await client.get(url, params=params)
|
36
|
+
r = await client.get(url, params=params, timeout=timeout)
|
37
37
|
return r.text
|
38
38
|
|
39
|
-
async def _aget_all(self, x, params):
|
40
|
-
return await asyncio.gather(*[self._aget_one(url, param) for url, param in zip(x, params)])
|
39
|
+
async def _aget_all(self, x, params, timeout):
|
40
|
+
return await asyncio.gather(*[self._aget_one(url, param, timeout) for url, param in zip(x, params)])
|
41
41
|
|
42
|
-
def _aget(self, x, params):
|
43
|
-
return pl.Series(asyncio.run(self._aget_all(x, params)))
|
42
|
+
def _aget(self, x, params, timeout):
|
43
|
+
return pl.Series(asyncio.run(self._aget_all(x, params, timeout)))
|
44
44
|
|
45
45
|
@staticmethod
|
46
|
-
async def _apost_one(url: str, params: str, body: str) -> str:
|
46
|
+
async def _apost_one(url: str, params: str, body: str, timeout: Optional[float]) -> str:
|
47
47
|
async with httpx.AsyncClient() as client:
|
48
|
-
r = await client.post(url, params=params, json=body)
|
48
|
+
r = await client.post(url, params=params, json=body, timeout=timeout)
|
49
49
|
return r.text
|
50
50
|
|
51
|
-
async def _apost_all(self, x, params, body):
|
51
|
+
async def _apost_all(self, x, params, body, timeout):
|
52
52
|
return await asyncio.gather(*[
|
53
|
-
self._apost_one(url, _params, _body) for url, _params, _body in zip(x, params, body)
|
53
|
+
self._apost_one(url, _params, _body, timeout) for url, _params, _body in zip(x, params, body)
|
54
54
|
])
|
55
55
|
|
56
|
-
def _apost(self, x, params, body):
|
57
|
-
return pl.Series(asyncio.run(self._apost_all(x, params, body)))
|
56
|
+
def _apost(self, x, params, body, timeout):
|
57
|
+
return pl.Series(asyncio.run(self._apost_all(x, params, body, timeout)))
|
58
58
|
|
59
|
-
def get(self, params: Optional[pl.Expr] = None) -> pl.Expr:
|
59
|
+
def get(self, params: Optional[pl.Expr] = None, timeout: Optional[float] = None) -> pl.Expr:
|
60
60
|
if params is None:
|
61
61
|
params = pl.lit(None)
|
62
62
|
return pl.struct(self._url.alias("url"), params.alias("params")).map_elements(
|
63
|
-
lambda x: self._get(x["url"], params=x["params"]),
|
63
|
+
lambda x: self._get(x["url"], params=x["params"], timeout=timeout),
|
64
64
|
return_dtype=pl.Utf8,
|
65
65
|
)
|
66
66
|
|
67
|
-
def post(
|
67
|
+
def post(
|
68
|
+
self, params: Optional[pl.Expr] = None, body: Optional[pl.Expr] = None, timeout: Optional[float] = None
|
69
|
+
) -> pl.Expr:
|
68
70
|
if params is None:
|
69
71
|
params = pl.lit(None)
|
70
72
|
if body is None:
|
71
73
|
body = pl.lit(None)
|
72
74
|
return pl.struct(self._url.alias("url"), params.alias("params"), body.alias("body")).map_elements(
|
73
|
-
lambda x: self._post(x["url"], params=x["params"], body=x["body"]),
|
75
|
+
lambda x: self._post(x["url"], params=x["params"], body=x["body"], timeout=timeout),
|
74
76
|
return_dtype=pl.Utf8,
|
75
77
|
)
|
76
78
|
|
77
|
-
def aget(self, params: Optional[pl.Expr] = None) -> pl.Expr:
|
79
|
+
def aget(self, params: Optional[pl.Expr] = None, timeout: Optional[float] = None) -> pl.Expr:
|
78
80
|
if params is None:
|
79
81
|
params = pl.lit(None)
|
80
82
|
return pl.struct(self._url.alias("url"), params.alias("params")).map_batches(
|
81
|
-
lambda x: self._aget(x.struct.field("url"), params=x.struct.field("params"))
|
83
|
+
lambda x: self._aget(x.struct.field("url"), params=x.struct.field("params"), timeout=timeout)
|
82
84
|
)
|
83
85
|
|
84
|
-
def apost(
|
86
|
+
def apost(
|
87
|
+
self, params: Optional[pl.Expr] = None, body: Optional[pl.Expr] = None, timeout: Optional[float] = None
|
88
|
+
) -> pl.Expr:
|
85
89
|
if params is None:
|
86
90
|
params = pl.lit(None)
|
87
91
|
if body is None:
|
88
92
|
body = pl.lit(None)
|
89
93
|
return pl.struct(self._url.alias("url"), params.alias("params"), body.alias("body")).map_batches(
|
90
|
-
lambda x: self._apost(
|
94
|
+
lambda x: self._apost(
|
95
|
+
x.struct.field("url"), params=x.struct.field("params"), body=x.struct.field("body"), timeout=timeout
|
96
|
+
)
|
91
97
|
)
|
@@ -0,0 +1,9 @@
|
|
1
|
+
examples/test.py,sha256=e-4VmxKdfRJZ01UN_3IAyAdnENTDGSZsrhGzJOtHwh0,927
|
2
|
+
polars_api/__init__.py,sha256=JoRS_iy8pZLEz_ADKooXOqOPlUQcd5wvdcSa_PMuGLs,40
|
3
|
+
polars_api/api.py,sha256=Pqfc7LJ3o4yx__s2JQ4lTwB12PjdtzImYvmO8pKxGOs,3830
|
4
|
+
tests/test_api.py,sha256=1OfyzFM1fUecl8TnY9CUkWt_zpUNgoIYnN_Ma9ZN77w,32
|
5
|
+
polars_api-0.1.5.dist-info/LICENSE,sha256=Ms_a-6jJtWdrIBCOaYS_hKFCODG2QXHcNgsQJnbujnA,1076
|
6
|
+
polars_api-0.1.5.dist-info/METADATA,sha256=eUtaFcZwWBXlcPc_sIpsQoTSi1YheIche_dxPVArs6M,3703
|
7
|
+
polars_api-0.1.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
+
polars_api-0.1.5.dist-info/top_level.txt,sha256=irGgxpseyd3aPqxnvE54AITFumMlSLGg1O9-zg5Gpac,26
|
9
|
+
polars_api-0.1.5.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
examples/test.py,sha256=e-4VmxKdfRJZ01UN_3IAyAdnENTDGSZsrhGzJOtHwh0,927
|
2
|
-
polars_api/__init__.py,sha256=JoRS_iy8pZLEz_ADKooXOqOPlUQcd5wvdcSa_PMuGLs,40
|
3
|
-
polars_api/api.py,sha256=XjGJu4Hhg_7aN_FmMqeH953sD7V1l1OS2F5JcNKJBaY,3341
|
4
|
-
tests/test_api.py,sha256=1OfyzFM1fUecl8TnY9CUkWt_zpUNgoIYnN_Ma9ZN77w,32
|
5
|
-
polars_api-0.1.4.dist-info/LICENSE,sha256=Ms_a-6jJtWdrIBCOaYS_hKFCODG2QXHcNgsQJnbujnA,1076
|
6
|
-
polars_api-0.1.4.dist-info/METADATA,sha256=8Vra2wJdHNE-h1MgOI8rNTUmT9pFDOD9VyRbyKaFp8U,3703
|
7
|
-
polars_api-0.1.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
8
|
-
polars_api-0.1.4.dist-info/top_level.txt,sha256=irGgxpseyd3aPqxnvE54AITFumMlSLGg1O9-zg5Gpac,26
|
9
|
-
polars_api-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|