-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
27 lines (20 loc) · 849 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import asyncio
from prototype import fetch_stream
async def main() -> None:
"""Example usage of AsyncArrowClient."""
url = "https://github.com/apache/arrow-experiments/raw/refs/heads/main/data/arrow-commits/arrow-commits.arrows"
print(f"Fetching Arrow stream from {url}")
reader = await fetch_stream(url, verbose=True)
batch_count = 0
row_count = 0
print("Starting async iteration")
async for batch in reader:
batch_count += 1
row_count += len(batch)
print(f"Processed batch {batch_count} with {len(batch)} rows")
await asyncio.sleep(0.01) # artificially slow down processing to illustrate async reading + writing
print(f"Finished processing batch {batch_count}")
print("Async iteration done")
if __name__ == "__main__":
import asyncio
asyncio.run(main())