Skip to content

StrategicProjects/apifetch-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

apifetch

apifetch (Python)

PyPI version Python versions CI Downloads License: MIT R sibling

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

About

A generic Python toolkit for token-authenticated REST API retrieval (sibling of the R package apifetch)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages