Skip to main content

Demands

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

Usage

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,
            expected_response_codes=[404])
        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(
    url='http://localhost/',
    headers={'h1':'value'},
    auth=('username','pass'),
)

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

Testing

Install development requirements:

pip install -r requirements.txt

Run the tests with:

nosetests

API documentation

To generate the documentation:

cd docs && PYTHONPATH=.. make singlehtml

Metadata

Release files for demands 5.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for demands 5.1.0
File Size Uploaded
demands-5.1.0.tar.gz 12.2 kB Details

Release files / demands-5.1.0.tar.gz

Download URL demands-5.1.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0309234bb3de4292c369164575ead0c3afc98bfa96d3db1e384ae34a78aaeb05
BLAKE2b-256 checksum
How to use checksums
42dac8a00be848fc0cee9d9d8383732fdc496945a6579eca8850a8d58bfa49ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

5.1.0 This release

1 release file

5.0.0

1 release file

4.1.0

1 release file

4.0.0

1 release file

3.0.0

1 release file

2.0.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.5

1 release file

1.1.4

1.1.3

1 release file

1.1.0

1 release file

1.0.6

1 release file

1.0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page