Skip to main content

A Requests session that returns awaitable Twisted Deferreds instead of response objects.

Project description

This repo contains a Requests session that returns awaitable Twisted Deferreds instead of Response objects.

It’s awesome, basically — check it out:

Examples

Example Usage (using async/await):

from requests_threads import AsyncSession

session = AsyncSession()

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.

Example Usage (using Twisted):

from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
import requests

session = requests.AsyncSession()

@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 Python 2 and Python 3.


Each request is sent via a new thread, automatically. This works fine for basic use cases.

This is a an experiment, and a preview of the true asyncronous API we have panned 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
✨🍰✨

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_threads-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

requests_threads-0.1.0-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file requests_threads-0.1.0.tar.gz.

File metadata

File hashes

Hashes for requests_threads-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3bfa8230da6b4e89834b41de3c59b390625d4163b36a53a0812ebca9ea2823c1
MD5 34cdd1adaa8e3cd4ed21997191b2dcb7
BLAKE2b-256 01a3a1dce7027ba5afc66fd239593c6d2cbded309e0e957e616aacfcd86395c2

See more details on using hashes here.

File details

Details for the file requests_threads-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for requests_threads-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b62b3226563dfcfab95aed185186d11be5512c9b042e7402ab0262c4646bf821
MD5 6039de61a1b12d348bad76ce60f41cd4
BLAKE2b-256 e6060e2f0f17bad77d1e597c38facc7506921447b856738cb996579b7210d2e1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page