Skip to main content

A wrapper for REST APIs

Project description

A wrapper for REST APIs

Maturity License Change Log Build Status Version

About

Syndicate is a library for using HTTP based REST APIs. This provides a means to generically handle serialization (JSON, XML) and URI mapping as seen in many of the REST APIs published these days. Currently Tastypie APIs are the primary target but the system should be compossible enough to work with other APIs if they work roughly the same way.

Requirements

  • Requests (sync mode)

  • aiohttp (async mode)

Installation

python ./setup.py build
python ./setup.py install

Compatibility

  • Python 3.4+

TODO

  • Unified authentication between HTTP adapters.

  • Documentation

Getting Started

Syndicate has two basic modes for communicating with an API, sync and async. The sync mode uses the ‘requests’ library as the HTTP adapter and the async mode uses aiohttp. An adapter can be provided by the user if they have their own backend.

In either mode, your interface is a ‘Service’ instance, which facilitates authentication, session management (via an adapter) and serialization.

Synchronous Examples

Creating a connnection

Instantiate a service class with some basic descriptions of the remote API to get a persistent connection.

import syndicate

bakery = syndicate.Service(uri='https://a.bakery.fake', urn='/api/v1/',
                           auth=('mrpresident', '1000xlight_points'))

Simple GET

Fetch all the resources at https://a.bakery.fake/api/v1/cake/

for x in bakery.get('cake'):
    print("Cake is food:", x)

Adding a new resource

new_owl = bakery.post('cake', {
    "type": "chuck_norris",
    "name": "Round House",
    "scovilles": 16000000001  # sorry resiniferatoxin
})

Non CRUD methods

If your service has non CRUD methods, you can ask a service to “do” things directly. Let’s “BAKE /api/v1/cake/100” with some instructions in the content body.

bakery.do('bake', 'cake', 100, temp=420, time=3600)

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

syndicate-2.tar.gz (10.1 kB view details)

Uploaded Source

File details

Details for the file syndicate-2.tar.gz.

File metadata

  • Download URL: syndicate-2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for syndicate-2.tar.gz
Algorithm Hash digest
SHA256 b59e279a432a77ec74ed48f911259cc0391f31ec8c0a951944dafa19af81d644
MD5 76729db9d147f53ee771bb54700238aa
BLAKE2b-256 33a80ffb6805f9f510d9c36d4e6b04adeb6ece3bd7b9e5dfd620142615d21e48

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