The easiest way to interact with the httpx library, including Sync and Async clients.
Simplify the way we have to interact with external urls and make requests (POST, GET, etc.).
Using this library is as simple and intuitive as doing this:
# Create an Async instance within this context
async with AsyncHttpClient() as http_client:
# Make a no-stream GET request
response = await http_client.get.complete(
url = url
)
# Create a Sync instance within this context
with HttpClient() as http_client:
# Make a no-stream GET request
response = http_client.get.complete(
url = url
)
or this:
# Create an Async client instance within a context
async with HttpClient() as http_client:
# Make a stream GET request
async with await http_client.get.stream(
url = url
) as response:
# Do whatever you need with the response
chunks_count = 0
bytes = b""
# Iterate over the bytes asynchronously
async for chunk in response.aiter_bytes(
chunk_size = chunk_size
):
bytes += chunk
chunks_count += 1
The resources are closed and freed once you are done. Easy.
She the tests to know more about how to use it.