Skip to main content

qrest is a Python package that allows you to easily build a Python client to access a REST API. To show how it works, we use it to access the REST API of the JSONPlaceholder website, which provides dummy data for testing and prototyping purposes.

The following Python snippet sends a HTTP GET request to retrieve all “posts”, which is one of the resources of the website:

import pprint
import requests

response = requests.request("GET", "https://jsonplaceholder.typicode.com/posts")
pprint.pprint(response.json()[0:2])

This snippet outputs:

[{'body': 'quia et suscipit\n'
          'suscipit recusandae consequuntur expedita et cum\n'
          'reprehenderit molestiae ut ut quas totam\n'
          'nostrum rerum est autem sunt rem eveniet architecto',
 'id': 1,
 'title': 'sunt aut facere repellat provident occaecati excepturi optio '
          'reprehenderit',
 'userId': 1},
{'body': 'est rerum tempore vitae\n'
         'sequi sint nihil reprehenderit dolor beatae ea dolores neque\n'
         'fugiat blanditiis voluptate porro vel nihil molestiae ut '
         'reiciendis\n'
         'qui aperiam non debitis possimus qui neque nisi nulla',
 'id': 2,
 'title': 'qui est esse',
 'userId': 1}]

The snippet uses the Python requests library to send the request. This library makes it very easy to query a REST API, but it requires the user to know the structure of the REST API, how to build calls to that API, how to parse responses etc. This is where qrest comes in: it allows you to configure a Python API that provides access to the information and hides the nitty-gritty details of writing REST API code. For example, using qrest the code to retrieve the posts looks like this:

import qrest
import jsonplaceholderconfig

api = qrest.API(jsonplaceholderconfig)

posts = api.all_posts()

If you want to retrieve the posts from a specific author:

import pprint

# all authors are numbered from 1 to 10
posts = api.filter_posts(user_id=7)

# only output the title of each post for brevity
titles = [post["title"] for post in posts]
pprint.pprint(titles)

which outputs:

['voluptatem doloribus consectetur est ut ducimus',
 'beatae enim quia vel',
 'voluptas blanditiis repellendus animi ducimus error sapiente et suscipit',
 'et fugit quas eum in in aperiam quod',
 'consequatur id enim sunt et et',
 'repudiandae ea animi iusto',
 'aliquid eos sed fuga est maxime repellendus',
 'odio quis facere architecto reiciendis optio',
 'fugiat quod pariatur odit minima',
 'voluptatem laborum magni']

The one thing you have to do is configure this API. The module jsonplaceholderconfig in the example above is configured like this:

from qrest import APIConfig, ResourceConfig, QueryParameter


class JSONPlaceholderConfig(APIConfig):
    url = "https://jsonplaceholder.typicode.com"


class AllPosts(ResourceConfig):

    name = "all_posts"
    path = ["posts"]
    method = "GET"
    description = "retrieve all posts"


class FilterPosts(ResourceConfig):

    name = "filter_posts"
    path = ["posts"]
    method = "GET"
    description = "retrieve all posts with a given title"

    user_id = QueryParameter(name="userId", description="the user ID of the author of the post")

For more information about qrest and its usage, we refer to the documentation.

If you want to contribute to qrest itself, we refer to the developer README that is located in the root directory of the repo.

Release files for qrest 4.2.2

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

Source distribution (sdist)

Source distribution for qrest 4.2.2
File Size Uploaded
qrest-4.2.2.tar.gz 36.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for qrest 4.2.2
File Interpreter ABI Platform
qrest-4.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 74.7 kB

Release files / qrest-4.2.2.tar.gz

Download URL qrest-4.2.2.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
62a874e0fc7f5ce54ea97bd7b743dff84f223bf61b60cc03a77bb412c55b820e
BLAKE2b-256 checksum
How to use checksums
247b0ae06faddc8a01a97f98f09f75e0c564a5c360147a278265c48b34ff21fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / qrest-4.2.2-py3-none-any.whl

Download URL qrest-4.2.2-py3-none-any.whl
Size 37.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90ad89caf2b7fe43dbfccebe7e2e00b9b86d0b683c7a08f66a078ce7f6f84f3b
BLAKE2b-256 checksum
How to use checksums
177d3afd8328df5c85e3df5e4eb18b8cd88428e0c859221ef2f5de0ae558cbda
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

4.2.2 This release

2 release files

4.1.2

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.1

2 release files

3.0.2

2 release files

3.0.1

3 release files

3.0.0

2 release files

2.99

2 release files

2.4.3

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.5

2 release files

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