Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Base class for building service clients on top of requests
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
demands Merge branch 'master'
tests Allow to set max retries.
.coveragerc Fix coveralls erroneous coverage data
.travis.yml 1.0.5 already pushed, removing changelog update
LICENSE Copy pasta typo Oops. Didn't mean to make that callable.
setup.cfg Initial implementation. Parse metadata from init Restore module metadata


Build Status Coverage Status Latest Version Downloads

A base HTTP service client.

By default it "demands" successful responses from API endpoints, otherwise it raises an exception.

Demands accepts all the same parameters as requests.request and extends the requests.Session class, documentation for both: Requests Developer Interface.

Written and used by the folks at Yola to support our free website builder.

HTTPServiceClient Overview

  • base class for creating service clients
  • provides flexible way of http error handling for descendants
  • HTTPServiceError raised on unexpected service response

  • Supports pre-send and post-send hooks


from demands import HTTPServiceClient

class MyService(HTTPServiceClient):
    def get_user(self, user_id):
        return self.get('/users/%s/' % user_id).json()

    def safe_get_user(self, user_id, default_user):
        response = self.get(
            '/users/%s/' % user_id, 
        return response.json() if response.is_ok else default_user

service = MyService(url='http://localhost/')
user = service.get_user(1234)

Any parameters passed to the constructor will also be used for each and every request:

service = MyService(

# sent with auth and both headers
user = service.get('/some-path', headers={'h2': 'kittens'})


Install development requirements:

pip install -r requirements.txt

Run the tests with:


API documentation

To generate the documentation:

cd docs && PYTHONPATH=.. make singlehtml
Something went wrong with that request. Please try again.