Simple pagination Pydantic BaseModel
Project description
Paginatic
Small Pydantic models for API pagination responses.
Features
- ID cursor pagination with
first_id,last_id, andhas_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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file paginatic-0.1.0.tar.gz.
File metadata
- Download URL: paginatic-0.1.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.12.13 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd66e7b371e7c452aad4d6d419cd94f6bfe71fee94b6509c7f2a295efaace81a
|
|
| MD5 |
86dcc45a9e5279e0dea9f38a186d5a7b
|
|
| BLAKE2b-256 |
45b1e79cc56051646b5e2e0cb84c95641e26341b45b1402bfb3e6e31fa544146
|
File details
Details for the file paginatic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: paginatic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.4 CPython/3.12.13 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8564d50ec13a58bea5affd79bfa45b1f7d9147d1084e4eba5201e654e2d1a6bf
|
|
| MD5 |
64c3d881a0011728c8e30239eba5d5fb
|
|
| BLAKE2b-256 |
ef7fc076adcea3cb899829cb650280ed18012a8f2b9e0334eab2262f628545f4
|