Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: upload progress #2725

Merged
merged 12 commits into from
Jul 13, 2023
32 changes: 32 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,38 @@ with tempfile.NamedTemporaryFile() as download_file:

![rich progress bar](img/rich-progress.gif)


trim21 marked this conversation as resolved.
Show resolved Hide resolved
## Monitoring upload progress

If you need to monitor upload progress of large responses, you can use request content generator streaming.

For example, showing a progress bar using the [`tqdm`](https://github.com/tqdm/tqdm) library.

```python
from pathlib import Path

import httpx
from tqdm import tqdm


def gen(p: Path):
with tqdm.tqdm(ascii=True, unit_scale=True, unit='B', unit_divisor=1024,
trim21 marked this conversation as resolved.
Show resolved Hide resolved
total=p.stat().st_size) as bar:
with p.open("rb") as f:
while data := f.read(4096):
yield data
bar.update(len(data))


file_to_upload = Path('...')

url = "..."
tomchristie marked this conversation as resolved.
Show resolved Hide resolved

httpx.post(url, content=gen(file_to_upload))
```

![tqdm progress bar](img/tqdm-progress.gif)

## .netrc Support

HTTPX can be configured to use [a `.netrc` config file](https://everything.curl.dev/usingcurl/netrc) for authentication.
Expand Down