Therapy to ease the pain of writing boilerplate code to consume JSON APIs.
Project description
python-therapi
Therapy to ease the pain of writing boilerplate JSON API consumers.
Tired of writing the same code to consume JSON APIs, over and over? Let's solve that!
Query a basic, public JSON API
To query any basic, public JSON API, we create our consumer class and inherit from BaseAPIConsumer
, as follows:
from therapi import BaseAPIConsumer
class MyAPIConsumer(BaseAPIConsumer):
base_url = "https://www.an-awesome-service.com/api"
Now we can use this class to make API calls to different endpoints, as follows:
consumer = MyAPIConsumer()
result = consumer.base_request(method="get", path="items")
print(result.json())
We would see, for example, this response:
{
"data": [
{"name": "Laptop", "price": 239},
{"name": "Printer", "price": 99}
]
}
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
therapi-0.0.2.tar.gz
(2.5 kB
view hashes)