Fido

Introduction

Fido is a simple, asynchronous HTTP client built on top of Crochet, Twisted and concurrent.futures. It is intended to be used in environments where there is no event loop, and where you cannot afford to spin up lots of threads (otherwise you could just use a ThreadPoolExecutor).

Here is an example of using Fido:

future = fido.fetch('http://www.yelp.com')
# Work happens in a background thread...
response = future.result(timeout=2)
print response.body

Frequently Asked Questions

Do you support SSL?

Yes, but I don’t know whether it’s secure; we should talk before you depend on this functionality. In more detail: Fido uses the Twisted defaults, which delegate to pyOpenSSL and service_identity for the actual SSL work.

Is the API stable?

Probably not. However, it is currently very simple, so it shouldn’t be hard to upgrade code if there’s a non backwards-compatible change.

Do I need to initialize Crochet?

No, crochet.setup is automatically invoked by fido.fetch().

How do I use an http_proxy?

Just set the http_proxy (all lowercase) environment variable to the URL of the http proxy before starting your python process.

Example:

$ export http_proxy="http://localhost:8000"
$ python -c "import fido; print fido.fetch("http://www.yelp.com").result().body

API

fido.fetch(url, method='GET', headers=None, body='', timeout=None, connect_timeout=None)[source]

Make an HTTP request.

Parameters:
  • url – the URL to fetch.
  • method – the HTTP method.
  • headers

    a dictionary mapping from string keys to lists of string values. For example:

    {
        'X-Foo': ['Bar'],
        'X-Baz': ['Quux'],
    }
    
  • body – the request body (must be of bytes type).
  • timeout – maximum allowed request time in seconds.
  • connect_timeout – maximum time allowed to establish a connection in seconds.
Returns:

a crochet EventualResult object which behaves as a future, .wait() can be called on it to retrieve the fido.fido.Response object. .wait() throws any exception occurred while performing the request. Eventual additional failures information is stored in the crochet EventualResult object as stated in the official documentation

class fido.Response(code, headers, body, reason)[source]

An HTTP response.

Variables:
  • code – the integer response code.
  • headers – a dictionary of response headers, mapping from string keys to lists of string values.
  • body – the response body.
  • reason – the http reason phrase.
json()[source]

Helper function to load a JSON response body.