Skip to main content

A Python wrapper for restmapper

Project description

RestMapper takes the pain out of integrating with RESTful APIs. It removes all of the complexity with writing API-specific code, and lets you focus all your energy on the important stuff. Here’s a quick example (using Twitter):

>>> Twitter = RestMapper("https://api.twitter.com/1.1/{path}.json")
>>> auth = OAuth1('YOUR_APP_KEY', 'YOUR_APP_SECRET', 'USER_OAUTH_TOKEN', 'USER_OAUTH_TOKEN_SECRET')
>>> twitter = Twitter(auth=auth)
>>> response = twitter.statuses.mentions_timeline()

Which will call https://api.twitter.com/1.1/statuses/mentions_timeline.json, authenticate the request using OAuth1, and return the response as JSON.

Installation

python-restmapper is available for download through the Python Package Index (PyPi). You can install it right away using pip or easy_install.

pip install restmapper

Usage

The first thing you need to do is generate a base RestMapper object that will allow you to instantiate a connection with a remote API.

>>> Twitter = RestMapper("https://api.twitter.com/1.1/{path}.json")

{path} is just a placeholder for the rest of the path. You’ll specify this later when making API calls.

Twitter’s API is protected by OAuth1, so the next step is to provide authentication. When integrating with any other API, any requests-compatible auth object can be provided.

>>> from requests_oauthlib import OAuth1
>>> auth = OAuth1('YOUR_APP_KEY', 'YOUR_APP_SECRET', 'USER_OAUTH_TOKEN', 'USER_OAUTH_TOKEN_SECRET')
>>> twitter = Twitter(auth=auth)

Now you can start making calls. The API object’s attributes and properties map one-to-one with the API you’re integrating with. E.g., the below:

>>> response = twitter.statuses.mentions_timeline()

…will request https://api.twitter.com/1.1/statuses/mentions_timeline.json. The path implied by the attribute syntax is inserted right where the path placeholder is in the Twitter object’s instantiation earlier.

If you want to pass in body data for a POST, provide a single argument to the call to the API, and specify “POST” as the first attribute. I.e.

>>> twitter.POST.my.request(data)

PATCH, PUT, GET, and POST are all supported. GET is currently the default.

Miscellaneous

By default, python-restmapper will return parsed JSON objects. If you’d like the raw response object for a request, just pass in parse_response=False as an argument to the API object.

Support

If you like this library, or need help implementing it, send us an email: hi@lionheartsw.com.

License

http://img.shields.io/pypi/l/restmapper.svg?style=flat

Apache License, Version 2.0. See LICENSE for details.

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

restmapper-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file restmapper-1.0.1.tar.gz.

File metadata

  • Download URL: restmapper-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for restmapper-1.0.1.tar.gz
Algorithm Hash digest
SHA256 05faeabe1b668328dba4eb3064b5f9545b9b7024d3d3c35e50fa0e799bf984e4
MD5 d8f241868f5ff0b38ae3e52e9c6f2dc7
BLAKE2b-256 6a728d72b1f4fa687074c98642548577d55315f2b656452f5ee7fc4df50815da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page