Skip to main content
python-restmapper
=================

|CI Status| |Version|

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):

.. code:: pycon

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()

Whoa, easy, right? This will call
https://api.twitter.com/1.1/statuses/mentions_timeline.json,
authenticate the request using OAuth1, and return the response as JSON.
The great thing is that there’s not much else you need to learn to
integrate with any other API. You just plug in the base URL format,
provide any optional authentication handlers (that requests provides),
and then just start making API calls.

See
`requests-cloudkit <https://github.com/lionheart/requests-cloudkit>`__
for an example of an authentication handler working with Apple’s
CloudKit which is compatible right out of the box with RestMapper.

Installation
------------

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.

.. code:: pycon

>>> 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 <http://docs.python-requests.org/en/latest/user/authentication/>`__
auth object can be provided.

.. code:: pycon

>>> 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:

.. code:: pycon

>>> 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.

.. code:: pycon

>>> 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-licenselicense-badgelicense-url:

License |License|
-----------------

Apache License, Version 2.0. See `LICENSE <https://github.com/lionheart/python-restmapper/blob/master/LICENSE>`__ for details.

.. raw:: html

<!-- Images -->

.. raw:: html

<!--
.. |downloads| image:: https://img.shields.io/pypi/dm/restmapper.svg?style=flat
.. _downloads: https://pypi.python.org/pypi/restmapper
-->

.. |CI Status| image:: https://img.shields.io/travis/lionheart/python-restmapper.svg?style=flat
:target: https://github.com/lionheart/python-restmapper/blob/master/https://travis-ci.org/lionheart/restmapper.py
.. |Version| image:: https://img.shields.io/pypi/v/restmapper.svg?style=flat
:target: https://github.com/lionheart/python-restmapper/blob/master/https://pypi.python.org/pypi/restmapper
.. |License| image:: http://img.shields.io/pypi/l/restmapper.svg?style=flat
:target: https://github.com/lionheart/python-restmapper/blob/master/LICENSE


Metadata

Release files for restmapper 2.0.1

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

Built distribution (wheel)

Table of built distributions (wheels) for restmapper 2.0.1
File Interpreter ABI Platform
restmapper-2.0.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / restmapper-2.0.1-py2.py3-none-any.whl

Download URL restmapper-2.0.1-py2.py3-none-any.whl
Size 8.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e755ab1de1b23e181ec057c3b1a86973e43f0c4510703817f6d5c95a1d58a348
BLAKE2b-256 checksum
How to use checksums
18d95e31e076a311b09adb5783616ffcad74834c25350a9d5cfd710f87afdcd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.0.1 This release

1 release file

2.0.0

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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