Skip to main content

Twisted adapter for the requests library.

Project description

DEPRECATION WARNING

If I have any improvements to make, I’ll make them to txrequests and not here.

Twisted adapter for the requests library

Tiny add-on for the requests HTTP library so it can be used transparently with Twisted by deferring blocking calls to threads.

It just wraps all requests in deferToThread, really.

Usage:

# To use requests with Twisted, you just need to use
# a our requests.Session subclass manually.
# See http://docs.python-requests.org/en/latest/user/advanced/
# for some informations about the Session class.
from requests_twisted import TwistedRequestsSession
session = TwistedRequestsSession()

# Then after, instead of doing requests.get|post|whatever(), you just do
# session.get|post|whatever().
# It returns a defer :
defer = session.get('http://github.com/sametmax/')
def print_status(response):
    print(response.url, response.status_code)

# Which you just handle as you would usually do.
defer.addCallback(print_status)

There are no changes to the request API, the only difference is the defer.

If you are doing a lot of requests, remember you can change the reactor thread pool by doing :

from twisted.internet import reactor
reactor.suggestThreadPoolSize(number_of_threads)

The default size of the thread pool depends on the reactor being used; the default reactor uses a minimum size of 5 and a maximum size of 10. Be careful that you understand threads and their resource usage before drastically altering the thread pool sizes.

Installation

pip install requests-twisted

Informations

Supports : Python 2.7 (maybe 2.6, I didn’t test it) Licence : Zlib

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-twisted-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file requests-twisted-0.1.2.tar.gz.

File metadata

File hashes

Hashes for requests-twisted-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7e460d7fe85c0c576df7a805889dd83c146507d6644d51002c03ed3eb6c0a85b
MD5 d16b92730ba57df056652323c8351ea8
BLAKE2b-256 223983fc4b42962b0b201b9df7be85108f9d9a2982c8cf4f86b75eabeaf4d343

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