{"library":"sqlakeyset","title":"Offset-free Paging for SQLAlchemy","type":"library","description":"sqlakeyset implements keyset-based paging for SQLAlchemy (both ORM and core). It provides an efficient alternative to traditional offset-based pagination, which can become slow with deep pages. The library supports SQLAlchemy 2.0, includes type hints, and is tested with PostgreSQL, MariaDB/MySQL, and SQLite. The current version is 2.0.1775222100. While no explicit release cadence is stated, the GitHub repository shows regular updates and contributions.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install sqlakeyset"],"cli":null},"imports":["from sqlakeyset import select_page","from sqlakeyset import get_page","from sqlakeyset.asyncio import select_page"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/djrobstep/sqlakeyset","docs":null,"changelog":null,"pypi":"https://pypi.org/project/sqlakeyset/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"from sqlalchemy import create_engine, select, String, Integer\nfrom sqlalchemy.orm import declarative_base, Session, Mapped, mapped_column\nfrom sqlakeyset import select_page\n\n# 1. Define Base\nBase = declarative_base()\n\n# 2. Define a simple model\nclass Book(Base):\n    __tablename__ = \"books\"\n    id: Mapped[int] = mapped_column(Integer, primary_key=True)\n    author: Mapped[str] = mapped_column(String(50))\n    title: Mapped[str] = mapped_column(String(100))\n\n    def __repr__(self):\n        return f\"Book(id={self.id}, author='{self.author}', title='{self.title}')\"\n\n# 3. Create an in-memory SQLite engine\nengine = create_engine(\"sqlite:///:memory:\")\n\n# 4. Create tables\nBase.metadata.create_all(engine)\n\n# 5. Insert some sample data\nwith Session(engine) as session:\n    session.add_all([\n        Book(author=\"Stephen King\", title=\"It\"),\n        Book(author=\"J.R.R. Tolkien\", title=\"The Hobbit\"),\n        Book(author=\"Stephen King\", title=\"The Stand\"),\n        Book(author=\"Frank Herbert\", title=\"Dune\"),\n        Book(author=\"J.R.R. Tolkien\", title=\"The Lord of the Rings\"),\n    ])\n    session.commit()\n\n# 6. Perform keyset pagination\nwith Session(engine) as session:\n    # Build a query with ordering, including a unique key (id) at the end\n    q = select(Book).order_by(Book.author, Book.title, Book.id)\n\n    # Get the first page\n    page1 = select_page(session, q, per_page=2)\n    print(f\"Page 1 items: {page1.items}\")\n    print(f\"Page 1 has next: {page1.paging.has_next}\")\n    print(f\"Page 1 next bookmark: {page1.paging.bookmark_next}\")\n\n    # Get the second page using the bookmark from the first page\n    if page1.paging.has_next:\n        page2 = select_page(session, q, per_page=2, bookmark=page1.paging.bookmark_next)\n        print(f\"Page 2 items: {page2.items}\")\n        print(f\"Page 2 has next: {page2.paging.has_next}\")\n        print(f\"Page 2 next bookmark: {page2.paging.bookmark_next}\")","lang":"python","description":"Demonstrates basic keyset pagination using `select_page` with a SQLAlchemy 2.0-style query, retrieving the first page and its bookmark for subsequent pages. It includes a simple model, in-memory SQLite setup, data insertion, and then the pagination logic.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"2.0.1775222100","pypi_latest":"2.0.1775222100","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3.5,"avg_import_s":0.91,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.76,"mem_mb":21.8,"disk_size":"44.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.6,"import_time_s":0.56,"mem_mb":21.8,"disk_size":"43M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.09,"mem_mb":24.5,"disk_size":"49.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.4,"import_time_s":0.95,"mem_mb":24.5,"disk_size":"48M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.09,"mem_mb":24.2,"disk_size":"40.9M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.1,"import_time_s":1.06,"mem_mb":24.2,"disk_size":"39M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.12,"mem_mb":24.1,"disk_size":"40.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.2,"import_time_s":1.07,"mem_mb":24.1,"disk_size":"39M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.74,"mem_mb":22.2,"disk_size":"42.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"sqlakeyset","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":4.1,"import_time_s":0.64,"mem_mb":22.1,"disk_size":"42M"}]}}