Skip to main content

chain

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_py

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.

Metadata

Release files for chain-py 0.1.7

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

Source distribution (sdist)

Source distribution for chain-py 0.1.7
File Size Uploaded Provenance
chain-py-0.1.7.tar.gz 3.6 kB Without provenance Details

Release files / chain-py-0.1.7.tar.gz

Download URL chain-py-0.1.7.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bbb6570a898947b973e2277e18991d248218c96b9a212e1829c5d8661a9d673d
BLAKE2b-256 checksum
How to use checksums
bd475a434f0f0eeb3b7e48547d1ef8c632caff108f365d7c1631c18f78a17d32
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for chain-py 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.7 This release

1 release file No provenance

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