Skip to main content

Make API wrapper in fast, easy.

Project description

PyPI PyPI - Downloads PyPI - License document

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

  1. Pass the API endpoint base URL to Client.
  2. Write the end of the endpoint of the API in the class attribute. (client.forecast -> /forecast)
  3. 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
# <Data> {"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.

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

lowrapper-1.0.3.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

lowrapper-1.0.3-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page