> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Httpx

> HTTPX is a fully featured HTTP client library for Python 3. It includes an integrated command line client, has support for both HTTP/1.1 and HTTP/2, and…

Web page: https://eugo.io/docs/ganymede/demo_notebooks/networking/utilities/httpx/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/networking/utilities/httpx/httpx.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/networking/utilities/httpx.ipynb)

Description:
- HTTPX is a fully featured HTTP client library for Python 3. It includes an integrated command line client, has support for both HTTP/1.1 and HTTP/2, and provides both sync and async APIs.

Resources:
- [GitHub] https://github.com/encode/httpx
- [Docs] https://www.python-httpx.org/

## Example 1

Get http status codes, headers, and text for a url

```python
import httpx

r = httpx.get('https://www.eugo.io/')

print(r.status_code)
print(r.headers['content-type'])
print(r.text)
```

## Example 2

Monitor Download Progress

```python
import tempfile
import httpx
from tqdm import tqdm


with tempfile.NamedTemporaryFile() as download_file:
    url = "https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz"
    with httpx.stream("GET", url) as response:
        total = int(response.headers["Content-Length"])

        with tqdm(total=total, unit_scale=True, unit_divisor=1024, unit="B") as progress:
            num_bytes_downloaded = response.num_bytes_downloaded
            for chunk in response.iter_bytes():
                download_file.write(chunk)
                progress.update(response.num_bytes_downloaded - num_bytes_downloaded)
                num_bytes_downloaded = response.num_bytes_downloaded
```

## Example 3

Making an async request

```python
import httpx

async def example_async():
    async with httpx.AsyncClient() as client:
        r = await client.get('https://www.eugo.io/')
        print(r)

# The notebook already runs an event loop, so await the coroutine directly
# (in a script, use asyncio.run(example_async()) instead)
await example_async()
```
