{"id":13469328,"url":"https://github.com/spyoungtech/grequests","last_synced_at":"2025-12-16T20:46:59.502Z","repository":{"id":3252325,"uuid":"4290214","full_name":"spyoungtech/grequests","owner":"spyoungtech","description":"Requests + Gevent = \u003c3","archived":false,"fork":false,"pushed_at":"2024-08-08T21:52:34.000Z","size":62,"stargazers_count":4558,"open_issues_count":11,"forks_count":332,"subscribers_count":113,"default_branch":"master","last_synced_at":"2025-04-24T01:53:15.694Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.python.org/pypi/grequests","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spyoungtech.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-05-10T21:50:15.000Z","updated_at":"2025-04-23T20:54:51.000Z","dependencies_parsed_at":"2024-11-18T14:06:14.947Z","dependency_job_id":"e0af0fa6-e5ff-4252-9a50-bfd20354aa6d","html_url":"https://github.com/spyoungtech/grequests","commit_stats":{"total_commits":66,"total_committers":27,"mean_commits":"2.4444444444444446","dds":0.7727272727272727,"last_synced_commit":"bb1cefeb346010780395fd6af4fda5b788432eb1"},"previous_names":["kennethreitz/grequests","not-kennethreitz/grequests"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fgrequests","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fgrequests/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fgrequests/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spyoungtech%2Fgrequests/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spyoungtech","download_url":"https://codeload.github.com/spyoungtech/grequests/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990466,"owners_count":21995774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:33.992Z","updated_at":"2025-12-16T20:46:59.465Z","avatar_url":"https://github.com/spyoungtech.png","language":"Python","readme":"GRequests: Asynchronous Requests\n===============================\n\nGRequests allows you to use Requests with Gevent to make asynchronous HTTP\nRequests easily.\n\n|version| |pyversions|\n\n\n\nInstallation\n------------\n\nInstallation is easy with pip::\n\n    $ pip install grequests\n    ✨🍰✨\n\n\nUsage\n-----\n\nUsage is simple:\n\n.. code-block:: python\n\n    import grequests\n\n    urls = [\n        'http://www.heroku.com',\n        'http://python-tablib.org',\n        'http://httpbin.org',\n        'http://python-requests.org',\n        'http://fakedomain/',\n        'http://kennethreitz.com'\n    ]\n\nCreate a set of unsent Requests:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e rs = (grequests.get(u) for u in urls)\n\nSend them all at the same time using ``map``:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e grequests.map(rs)\n    [\u003cResponse [200]\u003e, \u003cResponse [200]\u003e, \u003cResponse [200]\u003e, \u003cResponse [200]\u003e, None, \u003cResponse [200]\u003e]\n\n\nThe HTTP verb methods in ``grequests`` (e.g., ``grequests.get``, ``grequests.post``, etc.) accept all the same keyword arguments as in the ``requests`` library.\n\nError Handling\n^^^^^^^^^^^^^^\n\nTo handle timeouts or any other exception during the connection of\nthe request, you can add an optional exception handler that will be called with the request and\nexception inside the main thread. The value returned by your exception handler will be used in the result list returned by ``map``.\n\n\n.. code-block:: python\n\n    \u003e\u003e\u003e def exception_handler(request, exception):\n    ...    print(\"Request failed\")\n\n    \u003e\u003e\u003e reqs = [\n    ...    grequests.get('http://httpbin.org/delay/1', timeout=0.001),\n    ...    grequests.get('http://fakedomain/'),\n    ...    grequests.get('http://httpbin.org/status/500')]\n    \u003e\u003e\u003e grequests.map(reqs, exception_handler=exception_handler)\n    Request failed\n    Request failed\n    [None, None, \u003cResponse [500]\u003e]\n\n\nimap\n^^^^\n\nFor some speed/performance gains, you may also want to use ``imap`` instead of ``map``. ``imap`` returns a generator of responses. Order of these responses does not map to the order of the requests you send out. The API for ``imap`` is equivalent to the API for ``map``. You can also adjust the ``size`` argument to ``map`` or ``imap`` to increase the gevent pool size.\n\n\n.. code-block:: python\n\n    for resp in grequests.imap(reqs, size=10):\n        print(resp)\n\n\nThere is also an enumerated version of ``imap``, ``imap_enumerated`` which yields the index of the request from the original request list and its associated response. However, unlike ``imap``, failed requests and exception handler results that return ``None`` will also be yielded (whereas in ``imap`` they are ignored). Aditionally, the ``requests`` parameter for ``imap_enumerated`` must be a sequence. Like in ``imap``, the order in which requests are sent and received should still be considered arbitrary.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e rs = [grequests.get(f'https://httpbin.org/status/{code}') for code in range(200, 206)]\n    \u003e\u003e\u003e for index, response in grequests.imap_enumerated(rs, size=5):\n    ...     print(index, response)\n    1 \u003cResponse [201]\u003e\n    0 \u003cResponse [200]\u003e\n    4 \u003cResponse [204]\u003e\n    2 \u003cResponse [202]\u003e\n    5 \u003cResponse [205]\u003e\n    3 \u003cResponse [203]\u003e\n\ngevent - when things go wrong\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBecause ``grequests`` leverages ``gevent`` (which in turn uses monkeypatching for enabling concurrency), you will often need to make sure ``grequests`` is imported before other libraries, especially ``requests``, to avoid problems. See `grequests gevent issues \u003chttps://github.com/spyoungtech/grequests/issues?q=is%3Aissue+label%3A%22%3Ahear_no_evil%3A%3Asee_no_evil%3A%3Aspeak_no_evil%3A++gevent%22+\u003e`_ for additional information.\n\n\n.. code-block:: python\n\n    # GOOD\n    import grequests\n    import requests\n    \n    # BAD\n    import requests\n    import grequests\n\n\n\n\n\n\n\n.. |version| image:: https://img.shields.io/pypi/v/grequests.svg?colorB=blue\n    :target: https://pypi.org/project/grequests/\n\n.. |pyversions| image:: https://img.shields.io/pypi/pyversions/grequests.svg?\n    :target: https://pypi.org/project/grequests/\n    \n    \n","funding_links":[],"categories":["Python","接口工具","Containers \u0026 Language Extentions \u0026 Linting","HTTP Clients","HTTP","HTTP Clients [🔝](#readme)","Programming Languages"],"sub_categories":["For Python","Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyoungtech%2Fgrequests","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspyoungtech%2Fgrequests","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspyoungtech%2Fgrequests/lists"}