-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathasync_usage.py
More file actions
41 lines (28 loc) · 1.01 KB
/
Copy pathasync_usage.py
File metadata and controls
41 lines (28 loc) · 1.01 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Async usage examples for primp AsyncClient."""
import asyncio
import primp
async def basic_request():
"""Basic async GET request."""
async with primp.AsyncClient(impersonate="chrome_146") as client:
resp = await client.get("https://httpbin.org/get")
print(f"Status: {resp.status_code}")
print(f"Body: {resp.text[:100]}...")
async def concurrent_requests():
"""Multiple concurrent requests."""
urls = [
"https://httpbin.org/get",
"https://httpbin.org/ip",
"https://httpbin.org/headers",
]
async with primp.AsyncClient(impersonate="chrome_146") as client:
tasks = [client.get(url) for url in urls]
responses = await asyncio.gather(*tasks)
for resp in responses:
print(f"{resp.url}: {resp.status_code}")
async def main():
print("=== Basic Request ===")
await basic_request()
print("\n=== Concurrent Requests ===")
await concurrent_requests()
if __name__ == "__main__":
asyncio.run(main())