Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/requests/requests-threads
π Twisted Deferred Thread backend for Requests.
https://github.com/requests/requests-threads
async asyncio deferred requests threads twisted
Last synced: 3 months ago
JSON representation
π Twisted Deferred Thread backend for Requests.
- Host: GitHub
- URL: https://github.com/requests/requests-threads
- Owner: requests
- Created: 2017-09-04T14:40:02.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T15:53:58.000Z (over 5 years ago)
- Last Synced: 2024-07-31T14:48:59.832Z (3 months ago)
- Topics: async, asyncio, deferred, requests, threads, twisted
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 418
- Watchers: 16
- Forks: 27
- Open Issues: 9
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
- starred-awesome - requests-threads - π Twisted Deferred Thread backend for Requests. (Python)
README
requests-threads π
===================This repo contains a Requests session that returns the amazing `Twisted `_'s awaitable
Deferreds instead of Response objects.It's awesome, basically βΒ check it out:
.. image:: https://farm5.staticflickr.com/4418/35904417594_c4933a2171_k_d.jpg
Examples
--------Let's send 100 concurrent requests! \\o/
**Example Usage** using ``async``/``await`` β
.. code:: python
from requests_threads import AsyncSession
session = AsyncSession(n=100)
async def _main():
rs = []
for _ in range(100):
rs.append(await session.get('http://httpbin.org/get'))
print(rs)if __name__ == '__main__':
session.run(_main)*This example works on Python 3 only.* You can also provide your own ``asyncio`` event loop!
**Example Usage** using Twisted β
.. code:: python
from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from requests_threads import AsyncSession
session = AsyncSession(n=100)@inlineCallbacks
def main(reactor):
responses = []
for i in range(100):
responses.append(session.get('http://httpbin.org/get'))for response in responses:
r = yield response
print(r)if __name__ == '__main__':
react(main)*This example works on both Python 2 and Python 3.*
--------------------
Each request is sent via a new thread, automatically. This works fine for basic
use cases. This automatically uses Twisted's ``asyncioreactor``, if you do not
provide your own reactor (progress to be made there, help requested!).**This is a an experiment**, and a preview of the true asynchronous API we have planned for Requests
that is currently *in the works*, but requires a lot of development time. If you'd like to help (p.s. **we need help**, `send me an email `_).This API is likely to change, over time, slightly.
Installation
------------::
$ pipenv install requests-threads
β¨π°β¨Inspiration
-----------This codebase was inspired by future work on Requests, as well as `requests-twisted `_.