Skip to main content

Paginatic

PyPI version Python Version License

Small Pydantic models for API pagination responses.

Features

  • ID cursor pagination with first_id, last_id, and has_more
  • Token pagination with next_page_token
  • Signed opaque page-token helpers
  • Pydantic generic models for typed response data

Installation

pip install paginatic

Quick Start

from typing import Text

from pydantic import BaseModel

from paginatic import Paginatic, TokenPaginatic


class User(BaseModel):
    id: Text
    name: Text


id_page = Paginatic[User, Text](
    data=[User(id="user_1", name="Ada")],
    first_id="user_1",
    last_id="user_1",
    has_more=False,
)

token_page = TokenPaginatic[User](
    data=[User(id="user_1", name="Ada")],
    next_page_token="opaque-next-page-token",
)

ID Cursor Pagination

Use Paginatic when the response exposes item IDs as cursors.

page = Paginatic[User, Text](
    data=[
        {"id": "user_1", "name": "Ada"},
        {"id": "user_2", "name": "Grace"},
    ],
    first_id="user_1",
    last_id="user_2",
    has_more=True,
)

print(page.model_dump())

Output:

{
  "object": "list",
  "data": [
    {"id": "user_1", "name": "Ada"},
    {"id": "user_2", "name": "Grace"}
  ],
  "first_id": "user_1",
  "last_id": "user_2",
  "has_more": true
}

Token Pagination

Use TokenPaginatic when the next page is represented by an opaque server-generated token.

from paginatic.helpers import decode_and_verify, encode_and_sign

secret = "replace-me"

next_page_token = encode_and_sign(
    {
        "created_at": "2026-05-01T10:30:00Z",
        "id": "user_2",
        "sort": "created_at_desc",
        "version": 1,
    },
    secret=secret,
)

page = TokenPaginatic[User](
    data=[User(id="user_1", name="Ada"), User(id="user_2", name="Grace")],
    next_page_token=next_page_token,
)

payload = decode_and_verify(next_page_token, secret=secret)

Tokens are signed, not encrypted. Do not put secrets or private user data in token payloads.

Configuration

No configuration is required.

License

MIT License

Metadata

Release files for paginatic 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for paginatic 0.1.0
File Size Uploaded
paginatic-0.1.0.tar.gz 3.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for paginatic 0.1.0
File Interpreter ABI Platform
paginatic-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / paginatic-0.1.0.tar.gz

Download URL paginatic-0.1.0.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dd66e7b371e7c452aad4d6d419cd94f6bfe71fee94b6509c7f2a295efaace81a
BLAKE2b-256 checksum
How to use checksums
45b1e79cc56051646b5e2e0cb84c95641e26341b45b1402bfb3e6e31fa544146
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.13 Darwin/25.3.0

Release files / paginatic-0.1.0-py3-none-any.whl

Download URL paginatic-0.1.0-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8564d50ec13a58bea5affd79bfa45b1f7d9147d1084e4eba5201e654e2d1a6bf
BLAKE2b-256 checksum
How to use checksums
ef7fc076adcea3cb899829cb650280ed18012a8f2b9e0334eab2262f628545f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.13 Darwin/25.3.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page