Skip to main content

A Python wrapper for restmapper

Project description

civersiondownloads

python-restmapper is a tool that makes writing RESTful API clients a breeze. It removes all of the complexity with writing API-specific code, and lets you focus all your energy on the important stuff. Using Python-Requests, RestMapper will parse JSON and display responses nicely, based on a declarative format you provide for each API you integrate with (in progress).

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

No dependencies (besides Python 2.7).

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/", url_transformer=lambda url: url + ".json")

The next step is to provide authentication. For Twitter, you’ll need to provide OAuth1 credentials (for other APIs, any other requests-compatible auth object will do):

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

And start making calls. The API object is declarative, meaning that attributes and properties map 1-1 with the API you’re integrating with. I.e., the below:

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

…will request https://api.twitter.com/1.1/statuses/mentions_timeline.json. Notice the url_transformer object used above—this adds “.json” to any request. You can pass in any function into the url_transformer object to handle more complicated situations.

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 (more will come later). 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-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for restmapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 90a63c2f6e5560bba25fe61cd43d861acd5b79f51a9d68de3a51c75a33d50d8e
MD5 ad787dfedb91b8e3c38812aaf7d4ba8f
BLAKE2b-256 e6ec4efa69c75e111f4684a1be5b2685654989056c5dd21a1f9c70dfff9f2a56

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