Skip to content

Instantly share code, notes, and snippets.

@rkhullar
Created April 4, 2023 14:31
Show Gist options
  • Save rkhullar/758d8f24cc9e34a9b13f3b9165468490 to your computer and use it in GitHub Desktop.
Save rkhullar/758d8f24cc9e34a9b13f3b9165468490 to your computer and use it in GitHub Desktop.
httpx util
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