Metadata-Version: 2.4
Name: apifetch
Version: 0.1.0
Summary: A generic toolkit for token-authenticated REST API retrieval.
Project-URL: Homepage, https://github.com/StrategicProjects/apifetch-py
Project-URL: Repository, https://github.com/StrategicProjects/apifetch-py
Project-URL: R sibling, https://github.com/StrategicProjects/apifetch
Author-email: André Leite <leite@de.ufpe.br>
License: MIT License
        
        Copyright (c) 2026 André Leite
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: api,client,http,pagination,rest,token
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP
Requires-Python: >=3.9
Requires-Dist: httpx>=0.24
Provides-Extra: dev
Requires-Dist: pandas>=1.3; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: respx>=0.20; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
Provides-Extra: pandas
Requires-Dist: pandas>=1.3; extra == 'pandas'
Description-Content-Type: text/markdown

<p align="center">
  <img src="docs/assets/logo.png" width="200" alt="apifetch">
</p>

# 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](https://github.com/StrategicProjects/apifetch). Both were extracted
from the [BigDataPE](https://github.com/StrategicProjects/BigDataPE) package,
which is now one *use case* (see `examples/bigdatape.py`).

## Installation

```bash
pip install apifetch
```

## Usage

```python
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
