Skip to main content

A generic toolkit for token-authenticated REST API retrieval.

Project description

apifetch

apifetch (Python)

apifetch is a small, dependency-light toolkit for talking to token-authenticated REST APIs. It handles three recurring chores:

  1. Token management — store/get/remove/list tokens in process environment variables (never written to disk), namespaced per service.
  2. Request building — pluggable authentication and pagination strategies, bundled into a reusable Api profile.
  3. Data retrieval — fetch one page, or fetch everything in chunks.

This is the Python sibling of the R package apifetch. Both were extracted from the BigDataPE package, which is now one use case (see examples/bigdatape.py).

Installation

pip install apifetch

Usage

import apifetch as af

# 1. Describe the API once: where, how to authenticate, how to paginate.
api = af.Api(
    endpoint="https://api.example.com/v1/search",
    service="Example",
    auth=af.AuthBearer(),                 # "Authorization: Bearer <token>"
    pagination=af.PaginateOffset(where="query"),
)

# 2. Store a token (kept only in this process's environment).
af.store_token("reports", "my-secret-token", service="Example")

# 3. Fetch.
one_page = af.fetch(api, "reports", limit=50)
everything = af.fetch_all(api, "reports", chunk_size=1000)

# Optional: turn it into a DataFrame.
# import pandas as pd; df = pd.DataFrame(everything)

Strategies

Authentication: AuthBearer, AuthRaw, AuthHeader, AuthQuery.

Pagination: PaginateOffset(where="header" | "query"), PaginateNone.

License

MIT © André Leite

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

apifetch-0.1.0.tar.gz (49.4 kB view details)

Uploaded Source

Built Distribution

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

apifetch-0.1.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file apifetch-0.1.0.tar.gz.

File metadata

  • Download URL: apifetch-0.1.0.tar.gz
  • Upload date:
  • Size: 49.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apifetch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe8b0a16bcfb231ec7635f530cd6ff09f1113eab6b7b827a9b6e84e4b116194f
MD5 697a79770adb146556641935b473d6cc
BLAKE2b-256 ad0248186e6f091dd775d74d054d7f6a4aa3fd189f7ee5f56d37735e5ed46cfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for apifetch-0.1.0.tar.gz:

Publisher: release.yml on StrategicProjects/apifetch-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apifetch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: apifetch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apifetch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11940f6b0367c79e36a13f9cfdd9498942f5a5c9bc4d13c9366a14ef9eddc48d
MD5 b62f5aaf0996f7bd4f8c2cf539404987
BLAKE2b-256 38ce06b20135ec1617fb61fd192643e1f88cae48b3787ece5d4be7b01052d73c

See more details on using hashes here.

Provenance

The following attestation bundles were made for apifetch-0.1.0-py3-none-any.whl:

Publisher: release.yml on StrategicProjects/apifetch-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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