Skip to content

Async Client? #1

Description

@Ali-Parandeh

Hey guys, Thanks a lot for building this Python client. Just wondering if you have an async client baked in to the SDK? I normally can't use non-async clients since my whole API is async and it'll block the server

Use httpx or aiohttp package for sending HTTP requests to your server instead of requests package.

importjsonimportaiohttpfrom .encoderimportEncoderclassClient:
def__init__(self, config): ...
asyncdef_request(self, method, endpoint, payload=None):
url=f"{self.base_url}{endpoint}"asyncwithaiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=self.timeout)) assession:
asyncwithsession.request(
method,
url,
data=json.dumps(payload, cls=Encoder) ifpayloadisnotNoneelseNone
) asresponse:
response.raise_for_status()
returnawaitresponse.json()
asyncdefget(self, endpoint):
returnawaitself._request("GET", endpoint)
asyncdefpost(self, endpoint, payload=None):
returnawaitself._request("POST", endpoint, payload)
asyncdefput(self, endpoint, payload=None):
returnawaitself._request("PUT", endpoint, payload)
asyncdefdelete(self, endpoint, payload=None):
returnawaitself._request("DELETE", endpoint, payload)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions