Agnostic pagination in plain ruby
open sourceMITself-hostablefree
Pagy paginates Ruby collections in any environment, Rails or not: pagy(:offset, Product.all) (or :keyset, :countless, :calendar and others) returns a @pagy object and the page of records. It offers offset, count-free, keyset, keyset navigation, search and calendar pagination, renders navigation as plain HTML, Bootstrap or Bulma or with small client-side JavaScript helpers, and gives JSON:API links or a data hash for APIs. Version 43, released in November 2025 after 9.4, was a complete redesign of the API: the old extras became part of the core and the helpers became @pagy methods, with an upgrade guide for the move. Domizio Demichelis created it in 2018.
Problems it solves
- paginate a list in my Ruby app with a fast, light gem that doesn't need Rails
- page through millions of rows without a slow COUNT query and huge OFFSETs
- infinite scroll for an API that uses the last record's values instead of page numbers
- records shift between pages when new rows are inserted while someone is browsing
- paginate Elasticsearch, Meilisearch or Typesense search results with the same page links
- add JSON:API page[number] and page[size] links to a Rails API response
- browse records by year, month, week or day with page links inside each period
- Bootstrap or Bulma styled page links in a Ruby app without writing the markup
- page links that fit the container width on narrow mobile screens
- let API clients choose the page size but cap how many records they can ask for
- switch away from an older Rails pagination gem without rewriting every view
Features
- paginators: offset, countish, countless, keyset, keynav_js and calendar
- search paginators for elasticsearch_rails, meilisearch, rails_active_search, searchkick and typesense_rails
- keyset pagination for ActiveRecord::Relation and Sequel::Dataset
- server-rendered series_nav and info_tag; JavaScript series_nav_js, input_nav_js and limit_tag_js
- pagy, Bootstrap and Bulma styles
- JSON:API pagination and a data hash for JSON clients
- I18n locales autoloaded when used
- Pagy Wand dev tool to match your app's theme
- Pagy NEXT entry point to try the next major version early
- 100% test coverage for Ruby, HTML and JavaScript
Capabilities
| Has an API | plan not known |
|---|
Alternatives
The same job
These do what Pagy does.
- Kaminari A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for modern web app frameworks and ORMs
