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.4.tar.gz (4.7 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.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for polars_api-0.1.4.tar.gz
Algorithm Hash digest
SHA256 859722a89b1504625ec88b00832abe755cfdf9dc8fe5ed05016c6b15581014ab
MD5 7552c321ce69b48d96cb9f0238f17f47
BLAKE2b-256 df012a3cae2794bb7499a9850a0767167f4ded31cd49dbcbc34be7380991802d

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for polars_api-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3daa349bab5e8032a5077f2b1ca7811ccbe02cebc2a767a9b20d8405eb49edac
MD5 83a65bdf0ba013337c1743bcff21bf95
BLAKE2b-256 d6d12a4270bea4184aecaf9a57b6f1a383c49d5f50c870f866578072e4f3a6dc

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