polars-api 0.1.1__py3-none-any.whl → 0.1.2__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.
- polars_api/__init__.py +3 -0
- polars_api/api.py +40 -0
- {polars_api-0.1.1.dist-info → polars_api-0.1.2.dist-info}/METADATA +1 -1
- polars_api-0.1.2.dist-info/RECORD +8 -0
- {polars_api-0.1.1.dist-info → polars_api-0.1.2.dist-info}/top_level.txt +1 -0
- tests/test_api.py +2 -0
- polars_api-0.1.1.dist-info/RECORD +0 -5
- {polars_api-0.1.1.dist-info → polars_api-0.1.2.dist-info}/LICENSE +0 -0
- {polars_api-0.1.1.dist-info → polars_api-0.1.2.dist-info}/WHEEL +0 -0
polars_api/__init__.py
ADDED
polars_api/api.py
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
from typing import Optional
|
2
|
+
|
3
|
+
import httpx
|
4
|
+
import polars as pl
|
5
|
+
|
6
|
+
|
7
|
+
@pl.api.register_expr_namespace("api")
|
8
|
+
class Api:
|
9
|
+
def __init__(self, url: pl.Expr) -> None:
|
10
|
+
self._url = url
|
11
|
+
|
12
|
+
@staticmethod
|
13
|
+
def _get(url: str) -> Optional[str]:
|
14
|
+
result = httpx.get(url)
|
15
|
+
if result.status_code == 200:
|
16
|
+
return result.text
|
17
|
+
else:
|
18
|
+
return None
|
19
|
+
|
20
|
+
@staticmethod
|
21
|
+
def _post(url: str, body: str) -> Optional[str]:
|
22
|
+
result = httpx.post(url, json=body)
|
23
|
+
if result.status_code == 200:
|
24
|
+
return result.text
|
25
|
+
else:
|
26
|
+
return None
|
27
|
+
|
28
|
+
def get(self, params: Optional[pl.Expr] = None) -> pl.Expr:
|
29
|
+
return self._url.map_elements(
|
30
|
+
lambda x: self._get(x),
|
31
|
+
return_dtype=pl.Utf8,
|
32
|
+
)
|
33
|
+
|
34
|
+
def post(self, body: Optional[pl.Expr] = None) -> pl.Expr:
|
35
|
+
if body is None:
|
36
|
+
body = pl.lit("")
|
37
|
+
return pl.struct([self._url.alias("url"), body.alias("body")]).map_elements(
|
38
|
+
lambda x: self._post(x["url"], x["body"]),
|
39
|
+
return_dtype=pl.Utf8,
|
40
|
+
)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
polars_api/__init__.py,sha256=JoRS_iy8pZLEz_ADKooXOqOPlUQcd5wvdcSa_PMuGLs,40
|
2
|
+
polars_api/api.py,sha256=BU90-ZJQ5easjkRdzmrKM65JzQVzRqzpQxC33BT9Zus,1093
|
3
|
+
tests/test_api.py,sha256=1OfyzFM1fUecl8TnY9CUkWt_zpUNgoIYnN_Ma9ZN77w,32
|
4
|
+
polars_api-0.1.2.dist-info/LICENSE,sha256=Ms_a-6jJtWdrIBCOaYS_hKFCODG2QXHcNgsQJnbujnA,1076
|
5
|
+
polars_api-0.1.2.dist-info/METADATA,sha256=aVwOpJnazzO9xwz5j7CPHbWkAZJdhLn2Blc4bKBGXSM,4046
|
6
|
+
polars_api-0.1.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
7
|
+
polars_api-0.1.2.dist-info/top_level.txt,sha256=DB_mtsLtzuhP54ExuJV4MonMxWxqYnB8gpSywjrGN3A,17
|
8
|
+
polars_api-0.1.2.dist-info/RECORD,,
|
tests/test_api.py
ADDED
@@ -1,5 +0,0 @@
|
|
1
|
-
polars_api-0.1.1.dist-info/LICENSE,sha256=Ms_a-6jJtWdrIBCOaYS_hKFCODG2QXHcNgsQJnbujnA,1076
|
2
|
-
polars_api-0.1.1.dist-info/METADATA,sha256=kflG9Gkj7WD5rRZYZLx1JzCXHALbtQGLug9nHtvjMlQ,4046
|
3
|
-
polars_api-0.1.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
4
|
-
polars_api-0.1.1.dist-info/top_level.txt,sha256=8jrlIZHjbDXkT8co6HdxDmJ8hbSrMCCyUTF5XpxAc_w,11
|
5
|
-
polars_api-0.1.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|