Skip to main content

REST API calls made easier

Project description


REST API calls made easier

PyPI version Build Status Join the chat at


pip install resteasy

Usage and examples


from resteasy import RESTEasy, json

api = RESTEasy(base_url='',
               auth=('user', '****'),
               verify=False, cert=None, timeout=None,
               encoder=json.dumps, decoder=json.loads, debug=False)

# optional timeout
api.timeout = 60

Example 1: GitHub Jobs

api =  RESTEasy(base_url='')

positions = api.route('positions.json')

positions.get(description='python', full_time=1)
# or'GET', {'description': 'python', 'full_time': 1})


Example 2: All methods: GET, POST, PUT, PATCH, DELETE

from resteasy import RESTEasy

api = RESTEasy(base_url='')

posts = api.route('posts')

### GET (fetch resources)

### POST (create a resource)'foo', body='bar', userId=1)

### PUT & PATCH (update a resource)
posts.route(1).put(id=1, title='foo', body='bar', userId=1)

### DELETE (delete a resource)

Example 3: Chuck Norris jokes

from __future__ import print_function
from resteasy import RESTEasy

api = RESTEasy(base_url='')

### Print a random joke
jokes = api.route('jokes')
random = jokes.route('random')


### Get all categories
categories = jokes.route('categories').get()


### Print a random joke from each category
for category in categories:
    random_joke = random.get(category=category)
    print(category, ':', random_joke['value'])

    # GET<category>

Example 4: Using custom decoder: Parsing MyAnimeList HTML content

from resteasy import RESTEasy
from html.parser import HTMLParser

class MyHTMLParser(HTMLParser):
    '''Custom HTML parser'''

    def handle_starttag(self, tag, attrs):
        '''Overriding abstract method'''
        if tag == 'title' and not self.found:
            self.found = True

    def handle_data(self, data):
        '''Overriding abstract method'''
        if self.found and self.anime is None:
            self.anime = data

    def parse(self, content):
        '''Parse content and return object'''
        self.found = False
        self.anime = None
        title = self.anime.strip().replace(' -', '') if self.found else None
        return dict(title=title)

parser = MyHTMLParser()

api = RESTEasy(base_url='', decoder=parser.parse)

### One way

### Another way
api.route('anime', 1).get()

### Yet another way

### This is the last way I swear



To enable debugging just pass or set debug=True

api.debug = True

Once debugging is set to 'True', Every HTTP call will return debug information instead of doing the actual request

>>> posts.debug = True
>>> posts.get(userId=1)
{'endpoint': '',
 'kwargs': {'userId': 1},
 'method': 'GET',
 'session': <requests.sessions.Session at 0x7f1e8c8bfeb8>}


  • As this package uses requests module to perform HTTP calls, most exceptions will be raised by requests module itself.

  • In case API server returns HTTP status code outside the range of 200-299, It will raise resteasy.HTTPError

  • In case the returned content by API server is not parsable, It will raise resteasy.InvalidResponseError

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
RESTEasy-1.0.4-py3-none-any.whl (5.2 kB) Copy SHA256 hash SHA256 Wheel py3 Nov 1, 2018
RESTEasy-1.0.4.tar.gz (5.6 kB) Copy SHA256 hash SHA256 Source None Nov 1, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page