Skip to main content

An expressive clean way to interact with RESTful APIs.

Project description

Latest PyPI version Latest Travis CI build status

An expressive clean way to interact with REsTful APIs. It was inspired by zmallen’s pygraylog.

Chain is a small enhancement to the popular requests package. By referencing the endpoints as attributes to the client, it effectively “chains” the endpoints together, building the target url.

Chain is an attempt to make REsTful API clients look more like python objects, by removing the hardcoded URL strings in the code.

Chain uses the requests package as its http client, keeping its parameters and response objects. If you already use requests as your http client, then adopting chain would be easy.

Usage

Lets take for example this API:

# create a new client for the API
>>> import chain
>>> blogs = chain.Client('http://jsonplaceholder.typicode.com')

# if you want the posts:
>>> response = blogs.get.posts()

# the response is the response object from the requests package
>>> print response.json()

Numbers and special characters are also supported using dictionary notation

# Get the first post
>>> response = blogs.get.posts[1]()
>>> print response.json()

chain parameters are requests.requests parameters:

# parameters are the same as requests.requests parameters
>>> response = blogs.get.comments(params={'postId': '1'})
>>> print response.json()

>>> comment = {'postId': 1, 'id':501, 'name':'chain', 'email':'chain@code.com', 'body':'meh.'}
>>> response = blogs.post.comments(json=comment)

Installation

pip install chain-api

Testing

python setup.py test

Or:

tox

Compatibility

Works with Python version 2.7, 3.3, 3.4, 3.5 and 3.6

Licence

MIT licensed. Requests is licensed by the Apache License. See full LICENSE

Authors

chain was written by Anfernee Jervis.

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

chain-py-0.1.6.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file chain-py-0.1.6.tar.gz.

File metadata

  • Download URL: chain-py-0.1.6.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.3

File hashes

Hashes for chain-py-0.1.6.tar.gz
Algorithm Hash digest
SHA256 deb1c53c05dd65193d603f53d3839cc6b352b54abc6924e5a07abe0988269567
MD5 9b70174083baacb2cfeb62287b40c254
BLAKE2b-256 d69a2e968a2a2ff0e730a92d960bde5c183a6543a6ac3a07e01247d799a836b4

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