Skip to main content

Polars extension for dealing with REST APIs

Project description

polars-api

Release Build status codecov Commit activity License

Polars extension for dealing with REST APIs

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 struct type
  • 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

polars_api-0.1.6.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polars_api-0.1.6-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file polars_api-0.1.6.tar.gz.

File metadata

  • Download URL: polars_api-0.1.6.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for polars_api-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a710a43c9b7e3bf8cd69b1cba7b7f736e24ea45fae265c25dcd00f25d5bcb867
MD5 0b558016a491dd752079b4ca01add61b
BLAKE2b-256 436e883e27937add53449c83dbdec19edf5e3a8e75d7340e734b0f299c43c170

See more details on using hashes here.

File details

Details for the file polars_api-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: polars_api-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for polars_api-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0f3efabfa443914e1b3d44762a5a3e9fb5243a64482bec1281e6da2bbfca647e
MD5 dc7ef266c23d4f4a772841de74b105d3
BLAKE2b-256 d24cd73964c1cfdefcab1bf325884325f87bb17c4612d04bd3b28c7350a5ece2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page