HTTP Client API Reference¶
Auto-generated API documentation for the HTTP client module.
httpclient
¶
Zero-dependency sync + async HTTP REST client.
Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.
Sync (http.client) and async (asyncio streams) HTTP/1.1 client for REST API consumption. Thread-safe by design.
Sync usage::
response = get("https://httpbin.org/get")
response.json()
Async usage::
response = await async_get("https://httpbin.org/get")
response.json()
Session usage::
with Client() as client:
r = client.get("https://httpbin.org/get")
async with AsyncClient() as client:
r = await client.get("https://httpbin.org/get")
HttpClientError
¶
HTTPError
¶
Bases: HttpClientError
Raised on non-2xx status when raise_for_status() is called.
Source code in httpclient/httpclient.py
TooManyRedirects
¶
HttpConnectionError
¶
Bases: HttpClientError
Raised on connection failures.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
Remote hostname that the connection targeted. |
|
port |
Remote port number. |
|
message |
Human-readable error description. |
Source code in httpclient/httpclient.py
HttpTimeoutError
¶
Bases: HttpClientError
Raised on request timeout.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
The URL that timed out. |
|
timeout |
The timeout value in seconds that was exceeded. |
|
message |
Human-readable error description. |
Source code in httpclient/httpclient.py
Socks5Error
¶
Bases: HttpConnectionError
Raised on SOCKS5 proxy handshake failures.
Source code in httpclient/httpclient.py
Response
¶
HTTP response object.
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
HTTP status code. |
|
headers |
Response headers as dict (last value wins for duplicates). |
|
content |
Raw response body as bytes. |
|
url |
Final URL after redirects. |
Source code in httpclient/httpclient.py
Auth
¶
Base class for HTTP authentication.
Source code in httpclient/httpclient.py
auth_headers(method, url)
¶
Return authorization headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method. |
required |
url
|
str
|
Request URL. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict of headers to add to the request. |
Source code in httpclient/httpclient.py
BasicAuth
¶
Bases: Auth
HTTP Basic authentication.
Source code in httpclient/httpclient.py
auth_headers(method, url)
¶
Return Basic Authorization header.
DigestAuth
¶
Bases: Auth
HTTP Digest authentication.
Source code in httpclient/httpclient.py
auth_headers(method, url)
¶
auth_headers_from_challenge(method, path, challenge)
¶
Compute Digest auth headers from a WWW-Authenticate challenge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
HTTP method. |
required |
path
|
str
|
Request path (URI). |
required |
challenge
|
str
|
The WWW-Authenticate header value. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dict with the Authorization header. |
Source code in httpclient/httpclient.py
StreamingResponse
¶
HTTP streaming response -- holds the connection open.
Use as a context manager to ensure cleanup::
with get(url, stream=True) as r:
for chunk in r.iter_bytes():
process(chunk)
async with await async_get(url, stream=True) as r:
async for line in r.aiter_lines():
handle(line)
Source code in httpclient/httpclient.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
ok
property
¶
True if status_code is 2xx.
raise_for_status()
¶
iter_bytes(chunk_size=4096)
¶
Yield response body in chunks.
Source code in httpclient/httpclient.py
iter_lines()
¶
Yield response body line by line (decoded).
Source code in httpclient/httpclient.py
read()
¶
aiter_bytes(chunk_size=4096)
async
¶
Async yield response body in chunks.
Source code in httpclient/httpclient.py
aiter_lines()
async
¶
Async yield response body line by line (decoded).
Source code in httpclient/httpclient.py
aread()
async
¶
close()
¶
Close the underlying sync connection.
Source code in httpclient/httpclient.py
aclose()
async
¶
Close the underlying async connection.
Source code in httpclient/httpclient.py
Client
¶
Synchronous HTTP client session with connection pooling.
Thread-safe: the underlying connection pool uses its own
threading.Lock to protect shared state.
Usage::
with Client(headers={"Authorization": "Bearer token"}) as c:
r = c.get("https://api.example.com/data")
Source code in httpclient/httpclient.py
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 | |
request(method, url, **kwargs)
¶
Send an HTTP request.
Source code in httpclient/httpclient.py
AsyncClient
¶
Asynchronous HTTP client session with connection pooling.
Safe for concurrent use from multiple asyncio tasks. The underlying
connection pool uses its own asyncio.Lock to protect shared state.
Usage::
async with AsyncClient(headers={"Authorization": "Bearer token"}) as c:
r = await c.get("https://api.example.com/data")
Source code in httpclient/httpclient.py
2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 | |
request(method, url, **kwargs)
async
¶
Send an async HTTP request.