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 ADDED
@@ -0,0 +1,3 @@
1
+ from .api import Api
2
+
3
+ __all__ = ["Api"]
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
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: polars-api
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Polars extension for dealing with REST APIs
5
5
  Author-email: Diego Garcia Lozano <diegoglozano96@gmail.com>
6
6
  Project-URL: Homepage, https://diegoglozano.github.io/polars-api/
@@ -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
@@ -0,0 +1,2 @@
1
+ def test_get():
2
+ assert True
@@ -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,,