lowrapper
The lowrapper is a library for quickly and easily creating an environment for tapping the API without implementation.
Typing the Client
class creates a simple API wrapper with type completion.
Also, it may also be useful for creating API wrappers.
Let's start by looking at Simple Example below to see how it works.
Simple Example
This is the weather forecast API's low wrapper.
# 天気予報 API the low level wrapper
from lowrapper import Client, Response
client: Client[Response] = Client("https://weather.tsukumijima.net/api/")
print(client.forecast(method="GET", params={"city": 120010}).json())
# [GET] https://weather.tsukumijima.net/api/forecast?city=120010
This example uses the weather forecast API to get weather forecast information for Chiba Prefecture.
(Chiba Prefecture is a prefecture in Japan.)
Explanation for Simple Example
- Pass the API endpoint base URL to
Client
. - Write the end of the endpoint of the API in the class attribute. (
client.forecast
->/forecast
) - Hit the API.
As you can see, you can create an endpoint with Python class attributes.
You can also change the arguments for the request. (Let's see FAQs)
Installation
You can install lowrapper by running this command.
pip install lowrapper
If you want asynchronous lowrapper, you can get this by running this command.
pip install lowrapper[asynchronous]
or pip install aiohttp
FAQs
Q: I want to hit an endpoint that changes dynamically.
A: You can hit this by using like dictionary as follows.
client[YOUR_DYNAMIC_ENDPOINT]("GET", ...)
Q: I want to type the client class.
A: You can type by inheriting the client class as follows.
from lowrapper import Client, Path, Response
class Endpoint(Path[Response]):
ping: Path[Response]
class MySomeAPIClient(Client[Response]):
some: Endpoint
client = MySomeAPIClient("https://api.some.web/")
print(client.some.ping(method="GET").text)
# [GET] https://api.some.web/some/ping
# -> Some's PONG!
Q: I want to use asynchronous version of lowrapper.
A: You can use it by importing lowrapper.aio
as follows.
from lowrapper.aio import Client, Path, CoroutineResponse
client: Client[CoroutineResponse] = Client("https://asynchronous.love/")
And you should install aiohttp
to request.
Q: I want to change the request args.
A: You can change the request args like bellow.
from lowrapper import Client, Path, Method, Response
class MyClient(Client[Response]):
BASE = "https://simple.chat/"
def __init__(self):
super().__init__(self.BASE)
def send(self, message: str) -> Response:
return self.__request__(self, method="POST", json={"content": message})
client = MyClient()
client.send("Hi")
# [POST] https://simple.chat/send
# {"content": "Hi"}
Q: I want a guide.
A: Let's see documentation's guide.
Contributing
Let's cooperate by making an issue and submitting a Pull Request!
In case of Pull Request, please try not to change the style of the code. (65% PEP8)
Documentation
UserGuide and Documentation is here.