Created
July 5, 2024 16:13
-
-
Save 2tony2/097686e8b076dc58b5fb486b87648cf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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