requests-threads

? Twisted Deferred Thread backend for Requests.

Github星跟蹤圖

requests-threads ?

This repo contains a Requests session that returns the amazing Twisted <http://twistedmatrix.com/trac/>_'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 <mailto:me@kennethreitz.org>_).

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 <https://pypi.python.org/pypi/requests-twisted/>_.

主要指標

概覽
名稱與所有者requests/requests-threads
主編程語言Python
編程語言Python (語言數: 1)
平台
許可證
所有者活动
創建於2017-09-04 14:40:02
推送於2019-04-26 15:53:58
最后一次提交2018-10-25 13:23:01
發布數2
最新版本名稱v0.1.1 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數419
關注者數13
派生數27
提交數44
已啟用問題?
問題數8
打開的問題數8
拉請求數5
打開的拉請求數1
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?