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.5.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.5-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polars_api-0.1.5.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.5.tar.gz
Algorithm Hash digest
SHA256 81610a9d7900b7fae9bc258a3f93afbab029376034e7100f4fa40dbb57af1ef6
MD5 435241ce9f603ba441db912d9b4df9fc
BLAKE2b-256 0413d65450418751890090b9a1f278bc6b5a0e42c01d5b907c1c175feb3da0e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: polars_api-0.1.5-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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d41e0d6a00329e30b7b85640fa6b0b0c44a1826dda721e5966803031c6280367
MD5 95fb0722cecb78b85f2d5eacaf55c237
BLAKE2b-256 b779fdb79590dd62d6190fc88f4136c2083a73a9bb480155e567324dc9f8ed03

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