Polars extension for dealing with REST APIs
Project description
polars-api
Polars extension for dealing with REST APIs
- Github repository: https://github.com/diegoglozano/polars-api/
- Documentation https://diegoglozano.github.io/polars-api/
Installation
uv add polars-api
poetry add polars-api
pip install polars-api
Usage
Just import the library as import polars_api and the new api namespace will be available.
In the following example:
- We set a base URL using jsonplaceholder as a fake REST API
- For each row, we generate a different body using a
structtype - Finally, we call different methods for getting the data:
.api.get(): sync GET.api.aget(): async GET.api.post(): sync POST.api.apost(): async POST
These methods will return the result as a string, but with polars you can convert it easily in a struct and access its values using .str.json_decode() method.
import polars as pl
import polars_api
BASE_URL = "https://jsonplaceholder.typicode.com/posts"
df = (
pl
.DataFrame({
"url": [BASE_URL for _ in range(10)],
})
.with_columns(
pl
.struct(
title=pl.lit("foo"),
body=pl.lit("bar"),
userId=pl.arange(10),
)
.alias("body"),
)
.with_columns(
pl
.col("url")
.api.get()
.str.json_decode()
.alias("get"),
pl
.col("url")
.api.aget()
.str.json_decode()
.alias("aget"),
pl
.col("url")
.api.post(body=pl.col("body"))
.str.json_decode()
.alias("post"),
pl
.col("url")
.api.apost(body=pl.col("body"))
.str.json_decode()
.alias("apost"),
)
)
Repository initiated with fpgmaas/cookiecutter-uv.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_api-0.1.3.tar.gz.
File metadata
- Download URL: polars_api-0.1.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b426293742dd6775681bed772a8144ad61d9eb04b605d66670190dde7d2b37bc
|
|
| MD5 |
7960e813f84acc15e3deccbd435a12a2
|
|
| BLAKE2b-256 |
ef2d663767c64fd3f33d3e5da5f899a604b8dbd05a780bd5d0cb835d78ef5b76
|
File details
Details for the file polars_api-0.1.3-py3-none-any.whl.
File metadata
- Download URL: polars_api-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
219e95376615a5fb99ebb19d0bdad225693460a4b2a13dd99984b4fe07bf7ff0
|
|
| MD5 |
30de5738ee03593d37cbc620c886f8ce
|
|
| BLAKE2b-256 |
7dcb848f1b682ad5c55ccf098852528cf83b6f1575030506bcbcf7d885664bdd
|