Created
April 4, 2023 14:31
-
-
Save rkhullar/758d8f24cc9e34a9b13f3b9165468490 to your computer and use it in GitHub Desktop.
httpx util
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
import httpx | |
async def async_httpx(method: str, *args, verify: bool = True, **kwargs): | |
async with httpx.AsyncClient(verify=verify) as client: | |
fn = getattr(client, method) | |
return await fn(*args, **kwargs) | |
@dataclass | |
class BearerAuth(httpx.Auth): | |
token: str | |
def auth_flow(self, request): | |
request.headers['Authorization'] = f'Bearer {self.token}' | |
yield request |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment