httpcore

1.0.9 · active · verified Sat Mar 28

httpcore is a minimal, low-level HTTP/1.1 and HTTP/2 client library for Python, intended as a transport layer for higher-level clients such as httpx. It provides synchronous and (optionally) asynchronous connection pooling, SOCKS proxy support, streaming responses, and a 'trace' extension for request lifecycle introspection. Current stable version is 1.0.9 (April 2025). The project follows SEMVER and releases several times per year.

Warnings

Install

Imports

Quickstart

Demonstrates the one-off request helper, the recommended ConnectionPool pattern, streaming, and async usage.

import httpcore

# One-off request (no connection reuse)
response = httpcore.request('GET', 'https://httpbin.org/get')
print(response.status)   # int, e.g. 200
# Headers are List[Tuple[bytes, bytes]] — decode explicitly
for name, value in response.headers:
    print(name.decode(), value.decode())
print(response.content)  # bytes

# Production pattern: reuse a ConnectionPool
with httpcore.ConnectionPool() as http:
    r = http.request('GET', 'https://httpbin.org/get')
    print(r.status)

# Streaming large response
with httpcore.stream('GET', 'https://httpbin.org/stream-bytes/1024') as r:
    for chunk in r.iter_stream():
        pass  # process chunk (bytes)

# Async (requires: pip install 'httpcore[asyncio]')
import asyncio

async def main():
    async with httpcore.AsyncConnectionPool() as http:
        r = await http.request('GET', 'https://httpbin.org/get')
        print(r.status)

asyncio.run(main())

view raw JSON →