{ "info": { "author": "Todd Wolfson", "author_email": "todd@twolfson.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: Public Domain", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "api-pagination\n==============\n\n.. image:: https://travis-ci.org/underdogio/api-pagination.png?branch=master\n :target: https://travis-ci.org/underdogio/api-pagination\n :alt: Build Status\n\nPagination calculator designed for APIs\n\nWhen building an API, out of bound pages should be treated with empty result sets. The existing solutions were not doing this. We have designed ``api-pagination`` to handle these edge cases from the perspective of an API.\n\nGetting Started\n---------------\nInstall the module with: ``pip install api_pagination``\n\n.. code:: python\n\n # Load in dependencies\n from api_pagination import Paginator\n\n # Generate a paginator and get info about a page\n paginator = Paginator(total=100, items_per_page=10)\n page_info = paginator.get_page_info(page=2)\n {\n 'overall': {\n 'first_page': 1,\n 'last_page': 10,\n 'pages': 10,\n 'total': 100\n },\n 'page': {\n 'current_page': 2,\n 'next_page': 3,\n 'previous_page': 1\n }\n }\n\n # Use a classmethod to get info in one fell swoop\n page_info = Paginator.page_info(page=1, total=100, items_per_page=10)\n {\n 'overall': {\n 'first_page': 1,\n 'last_page': 10,\n 'pages': 10,\n 'total': 100\n },\n 'page': {\n 'current_page': 1,\n 'next_page': 2,\n 'previous_page': None\n }\n }\n\n # Handle out of bounds properly\n page_info = Paginator.page_info(page=20, total=100, items_per_page=10)\n {\n 'overall': {\n 'first_page': 1,\n 'last_page': 10,\n 'pages': 10,\n 'total': 100\n },\n 'page': {\n 'current_page': 20,\n 'next_page': None,\n 'previous_page': 10\n }\n }\n\n\nDocumentation\n-------------\nWe expose the ``Paginator`` class via our package ``api_pagination``\n\nPaginator(total, items_per_page)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nClass for calculating pagination info about items\n\n- total ``int`` - Overall amount of items present\n- items_per_page ``int`` - How many items to include on each page\n\npaginator.get_page_info(page)\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\nGather information about a given page\n\n- page ``int`` - Human based index for a page\n\n - For example, page 1 will be for items 1-10 (where ``items_per_page=10``)\n\n**Returns:**\n\n- ret_val ``dict`` - Container for information about overall information and page specific information\n\n - overall ``dict`` - Container for overall information\n\n - first_page ``int`` - Human based index for first page\n\n - For example, with ``total=20`` and ``items_per_page=10``, we have ``first_page=1``\n\n - last_page ``int`` - Human based index for last page\n\n - For example, with ``total=25`` and ``items_per_page=10``, we have ``last_page=3`` (includes items 21-25)\n\n - pages ``int`` - Amount of pages overall\n\n - For example, with ``total=25`` and ``items_per_page=10``, we have ``pages=3``\n\n - total ``int`` - Amount of items overall\n\n - page ``dict`` - Container for page specific information\n\n - current_page ``int`` - Human based index of requested page\n - next_page ``int|None`` - If there is another page after this one, ``next_page`` will be that page's human based index\n\n - For example, with ``total=25``, ``items_per_page=10``, and ``page=2``, we have ``next_page=3`` (includes items 21-25)\n - When on the last page (e.g. `total=25`, ``items_per_page=10``, ``page=3``) ``next_page`` will be ``None``\n - If we are under bounds (e.g. ``page=-1``), then ``next_page`` will be the first page (``page=1``)\n\n - previous_page ``int|None`` - If there is another page before this one, ``previous_page`` will be that page's human based index\n\n - For example, with ``total=25``, ``items_per_page=10``, and ``page=2``, we have ``previous_page=1`` (includes items 1-10)\n - When on the first page (e.g. ``total=25``, ``items_per_page=10``, ``page=1``) then ``previous_page`` will be ``None``\n - If we are over bounds (e.g. ``total=25``, ``items_per_page=10``, ``page=4``), then ``previous_page`` will be the last page (``page=3``)\n\nPaginator.page_info(page, \\*args, \\*\\*kwargs)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nHelper function to get page info without calling multiple actions\n\n- page ``int`` - Page to pass through to ``paginator.get_page_info``\n- \\*args - Ordered arguments to pass through to ``Paginator`` constructor\n- \\*\\*kwargs - Keyword based arguments to pass through to ``Paginator`` constructor\n\n**Returns:**\n\nReturns same format as ``paginator.get_page_info``\n\n**Example:**\n\n.. code:: python\n\n page_info = Paginator.page_info(page=1, total=100, items_per_page=10)\n # Same as\n # paginator = Paginator(total=100, items_per_page=10)\n # page_info = paginator.get_page_info(page=1)\n\n\nContributing\n------------\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Test via ``./test.sh``.\n\nLicense\n-------\nCopyright (c) 2015 Underdog.io\n\nLicensed under the MIT license.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/underdogio/api-pagination/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/underdogio/api-pagination", "keywords": "paginate,pagination,calc,calculate,calculator,api", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "api_pagination", "package_url": "https://pypi.org/project/api_pagination/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/api_pagination/", "project_urls": { "Download": "https://github.com/underdogio/api-pagination/archive/master.zip", "Homepage": "https://github.com/underdogio/api-pagination" }, "release_url": "https://pypi.org/project/api_pagination/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Pagination calculator designed for APIs", "version": "1.0.0" }, "last_serial": 1523158, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "bf1dc7c8011e0747aa409e4e85c38a20", "sha256": "2e88c5452aa20787ec442d4e7891854050e6ef6f959f10a355aaa695cce02d88" }, "downloads": -1, "filename": "api_pagination-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bf1dc7c8011e0747aa409e4e85c38a20", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7688, "upload_time": "2015-04-27T17:23:24", "url": "https://files.pythonhosted.org/packages/4f/29/738a70c1b1336b758441c13c1bd80704861ecb06131825c1bef22a61bae1/api_pagination-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "25944bfa44ad2a7708089bdfc0bd50c4", "sha256": "481674002f8899087d85ab526ac86dab94ba8888923e981c5b2646773cf2191d" }, "downloads": -1, "filename": "api_pagination-1.0.0.zip", "has_sig": false, "md5_digest": "25944bfa44ad2a7708089bdfc0bd50c4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15440, "upload_time": "2015-04-27T17:23:27", "url": "https://files.pythonhosted.org/packages/0b/ee/338b212113db7e8effe309640a319a8468ad2408ad9f5b0e61ed4744e492/api_pagination-1.0.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bf1dc7c8011e0747aa409e4e85c38a20", "sha256": "2e88c5452aa20787ec442d4e7891854050e6ef6f959f10a355aaa695cce02d88" }, "downloads": -1, "filename": "api_pagination-1.0.0.tar.gz", "has_sig": false, "md5_digest": "bf1dc7c8011e0747aa409e4e85c38a20", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7688, "upload_time": "2015-04-27T17:23:24", "url": "https://files.pythonhosted.org/packages/4f/29/738a70c1b1336b758441c13c1bd80704861ecb06131825c1bef22a61bae1/api_pagination-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "25944bfa44ad2a7708089bdfc0bd50c4", "sha256": "481674002f8899087d85ab526ac86dab94ba8888923e981c5b2646773cf2191d" }, "downloads": -1, "filename": "api_pagination-1.0.0.zip", "has_sig": false, "md5_digest": "25944bfa44ad2a7708089bdfc0bd50c4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15440, "upload_time": "2015-04-27T17:23:27", "url": "https://files.pythonhosted.org/packages/0b/ee/338b212113db7e8effe309640a319a8468ad2408ad9f5b0e61ed4744e492/api_pagination-1.0.0.zip" } ] }