Skip to content

Instantly share code, notes, and snippets.

@2tony2
Created July 5, 2024 16:13
Show Gist options
  • Save 2tony2/097686e8b076dc58b5fb486b87648cf0 to your computer and use it in GitHub Desktop.
Save 2tony2/097686e8b076dc58b5fb486b87648cf0 to your computer and use it in GitHub Desktop.
import httpx
def stream_data_from_api(url, chunk_size=1024):
with httpx.stream('GET', url) as response:
for chunk in response.iter_bytes(chunk_size):
yield chunk
# Example usage
url = '<https://example.com/large_file.zip>'
for chunk in stream_data_from_api(url):
# Process each chunk
print(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment