{ "info": { "author": "Sanhe Hu", "author_email": "husanhe@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows", "Operating System :: Unix", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": ".. image:: https://travis-ci.org/MacHu-GWU/apipool-project.svg?branch=master\n :target: https://travis-ci.org/MacHu-GWU/apipool-project?branch=master\n\n.. image:: https://codecov.io/gh/MacHu-GWU/apipool-project/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/MacHu-GWU/apipool-project\n\n.. image:: https://img.shields.io/pypi/v/apipool.svg\n :target: https://pypi.python.org/pypi/apipool\n\n.. image:: https://img.shields.io/pypi/l/apipool.svg\n :target: https://pypi.python.org/pypi/apipool\n\n.. image:: https://img.shields.io/pypi/pyversions/apipool.svg\n :target: https://pypi.python.org/pypi/apipool\n\n.. image:: https://img.shields.io/badge/Star_Me_on_GitHub!--None.svg?style=social\n :target: https://github.com/MacHu-GWU/apipool-project\n\n\nWelcome to ``apipool`` Documentation\n==============================================================================\n\n``apipool`` allows developer manipulate multi api key at same time. For example, if single api key has 1k/day quota, then you can register 10 api keys, and let ``apipool`` to automatically rotate the key.\n\n\n**Features**:\n\n- automatically rotate apikey.\n- built-in usage statistics, easy to search by ``time``, ``status``, ``apikey``. You can deploy stats collector on any cloud relational database.\n- clean api, minimal code is required to implement complex feature.\n\n\n**Example**:\n\nthere's a google geocoding example at: https://github.com/MacHu-GWU/apipool-project/blob/master/examples/google_geocoding.py\n\n\n**Tutorial**\n\nLet's walk through with a twitter api example, the api client we use is ``python-twitter``: https://github.com/bear/python-twitter.\n\nThe ``python-twitter`` usage:\n\n.. code-block:: python\n\n import twitter\n\n # create api client\n api = twitter.Api(\n consumer_key=\"consumer_key\"z,\n consumer_secret=\"consumer_secret\",\n access_token_key=\"access_token\",\n access_token_secret=\"access_token_secret\",\n )\n\n # make api call\n statuses = api.GetUserTimeline(screen_name=\"trump\")\n\n\nThe ``apipool`` usage:\n\n.. code-block:: python\n\n import twitter\n from apipool import ApiKey, ApiKeyManager\n\n class TwitterApiKey(ApiKey):\n def __init__(self,\n consumer_key,\n consumer_secret,\n access_token_key,\n access_token_secret)\n self.consumer_key = consumer_key\n self.consumer_secret = consumer_secret\n self.access_token_key = access_token_key\n self.access_token_secret = access_token_secret\n\n def user_01_get_primary_key(self):\n return self.access_token_key\n\n def user_02_create_client(self):\n return twitter.Api(\n consumer_key=self.consumer_key,\n consumer_secret=self.consumer_secret,\n access_token_key=self.access_token_key,\n access_token_secret=self.access_token_secret,\n )\n\n def user_03_test_usable(self, client):\n statuses = client.GetUserTimeline(screen_name=\"trump\")\n if len(statuses) >= 5:\n return True\n else:\n return False\n\n apikey_data_list = [\n {\n \"consumer_key\": xxx,\n \"consumer_secret\": xxx,\n \"access_token_key\": xxx,\n \"access_token_secret\": xxx,\n },\n {...},\n {...},\n ]\n\n apikey_list = [\n TwitterApiKey(**apikey_data)\n for apikey_data in apikey_data_list\n ]\n\n manager = ApiKeyManager(apikey_list=apikey_list)\n\n\n**DummyClient**:\n\nnow we can use the ``manager.dummyclient`` object like how we use the ``twitter.Api()`` object. However, the apikey is automatically rotated, and usage events are also automatically recorded.\n\n.. code-block:: python\n\n manager.check_usable()\n\n # the api key is automatically rotated under the hood\n statuses = manager.dummyclient.GetUserTimeline(screen_name=\"trump\")\n\n for _ in range(10):\n manager.dummyclient.GetUserTimeline(screen_name=\"trump\")\n\n\n**StatsCollector**:\n\nnow we can use ``manager.stats`` object to access usage stats, and also query usage events.\n\n.. code-block:: python\n\n >>> manager.stats.usage_count_stats_in_recent_n_seconds()\n {\"xxx access_token_key\": 3, \"xxx access_token_key\": 4, \"xxx access_token_key\": 3}\n\n >>> from apipool import StatusCollection\n >>> events_list = list(manager.stats.query_event_in_recent_n_seconds(\n n_seconds=24*3600,\n status_id=StatusCollection.c1_Success.id,\n ))\n >>> events_list\n [\n Event(apikey_id=xxx, finished_at=datetime(xxx), status_id=xxx),\n Event(...),\n ...\n ]\n\n\nQuick Links\n------------------------------------------------------------------------------\n- .. image:: https://img.shields.io/badge/Link-Document-red.svg\n :target: https://apipool.readthedocs.io/index.html\n\n- .. image:: https://img.shields.io/badge/Link-API_Reference_and_Source_Code-red.svg\n :target: https://apipool.readthedocs.io/py-modindex.html\n\n- .. image:: https://img.shields.io/badge/Link-Install-red.svg\n :target: `install`_\n\n- .. image:: https://img.shields.io/badge/Link-GitHub-blue.svg\n :target: https://github.com/MacHu-GWU/apipool-project\n\n- .. image:: https://img.shields.io/badge/Link-Submit_Issue_and_Feature_Request-blue.svg\n :target: https://github.com/MacHu-GWU/apipool-project/issues\n\n- .. image:: https://img.shields.io/badge/Link-Download-blue.svg\n :target: https://pypi.python.org/pypi/apipool#downloads\n\n\n.. _install:\n\nInstall\n------------------------------------------------------------------------------\n\n``apipool`` is released on PyPI, so all you need is:\n\n.. code-block:: console\n\n $ pip install apipool\n\nTo upgrade to latest version:\n\n.. code-block:: console\n\n $ pip install --upgrade apipool\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "https://pypi.python.org/pypi/apipool/0.0.2#downloads", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/MacHu-GWU/", "keywords": "", "license": "MIT", "maintainer": "Sanhe Hu", "maintainer_email": "husanhe@gmail.com", "name": "apipool", "package_url": "https://pypi.org/project/apipool/", "platform": "Windows", "project_url": "https://pypi.org/project/apipool/", "project_urls": { "Download": "https://pypi.python.org/pypi/apipool/0.0.2#downloads", "Homepage": "https://github.com/MacHu-GWU/" }, "release_url": "https://pypi.org/project/apipool/0.0.2/", "requires_dist": [ "sqlalchemy-mate (>=0.0.4)" ], "requires_python": "", "summary": "Multiple API Key Manager", "version": "0.0.2" }, "last_serial": 4194477, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "2733153de32a3efdceefed9be28ccde2", "sha256": "f92d808efe6b8106e642a06982c7db5ecdaf863398482f2e17278000690f1b42" }, "downloads": -1, "filename": "apipool-0.0.1.zip", "has_sig": false, "md5_digest": "2733153de32a3efdceefed9be28ccde2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13906, "upload_time": "2017-04-03T17:41:59", "url": "https://files.pythonhosted.org/packages/99/ac/43f605114ca20ed122d5a2171e84c47097af8105b7c1c1b04da804fb97be/apipool-0.0.1.zip" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "1d8722a918c63119cb59501aa8647105", "sha256": "22de13f9edbe98e7bcfbcfb1eab5ac429bca6fbda4996f0d59f6df2a2503d8b6" }, "downloads": -1, "filename": "apipool-0.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "1d8722a918c63119cb59501aa8647105", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 43487, "upload_time": "2018-08-22T00:32:43", "url": "https://files.pythonhosted.org/packages/19/14/31b3637c33a9b2374a0d708fb4b259edaa33b4a33f34e93c4eeba9d80d74/apipool-0.0.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fe51eb27c9c09a3a6861bf42bced5108", "sha256": "dcc8f01519f2fe6f9e06e560a976dc26c691d40efd088e69a1cf28d58f159613" }, "downloads": -1, "filename": "apipool-0.0.2.tar.gz", "has_sig": false, "md5_digest": "fe51eb27c9c09a3a6861bf42bced5108", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25189, "upload_time": "2018-08-22T00:32:45", "url": "https://files.pythonhosted.org/packages/f6/cd/e02256acb17d5692897f2b7b5b69ba863e3b926a1cd502402308905a8c18/apipool-0.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1d8722a918c63119cb59501aa8647105", "sha256": "22de13f9edbe98e7bcfbcfb1eab5ac429bca6fbda4996f0d59f6df2a2503d8b6" }, "downloads": -1, "filename": "apipool-0.0.2-py2-none-any.whl", "has_sig": false, "md5_digest": "1d8722a918c63119cb59501aa8647105", "packagetype": "bdist_wheel", "python_version": "py2", "requires_python": null, "size": 43487, "upload_time": "2018-08-22T00:32:43", "url": "https://files.pythonhosted.org/packages/19/14/31b3637c33a9b2374a0d708fb4b259edaa33b4a33f34e93c4eeba9d80d74/apipool-0.0.2-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fe51eb27c9c09a3a6861bf42bced5108", "sha256": "dcc8f01519f2fe6f9e06e560a976dc26c691d40efd088e69a1cf28d58f159613" }, "downloads": -1, "filename": "apipool-0.0.2.tar.gz", "has_sig": false, "md5_digest": "fe51eb27c9c09a3a6861bf42bced5108", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 25189, "upload_time": "2018-08-22T00:32:45", "url": "https://files.pythonhosted.org/packages/f6/cd/e02256acb17d5692897f2b7b5b69ba863e3b926a1cd502402308905a8c18/apipool-0.0.2.tar.gz" } ] }