Give AlbumentationsX a star on GitHub — it powers this leaderboard

Star on GitHub

httpcore

A minimal low-level HTTP client.

Downloads: 0 (30 days)

Description

HTTP Core

Test Suite Package version

Do one thing, and do it well.

The HTTP Core package provides a minimal low-level HTTP client, which does one thing only. Sending HTTP requests.

It does not provide any high level model abstractions over the API, does not handle redirects, multipart uploads, building authentication headers, transparent HTTP caching, URL parsing, session cookie handling, content or charset decoding, handling JSON, environment based configuration defaults, or any of that Jazz.

Some things HTTP Core does do:

  • Sending HTTP requests.
  • Thread-safe / task-safe connection pooling.
  • HTTP(S) proxy & SOCKS proxy support.
  • Supports HTTP/1.1 and HTTP/2.
  • Provides both sync and async interfaces.
  • Async backend support for asyncio and trio.

Requirements

Python 3.8+

Installation

For HTTP/1.1 only support, install with:

$ pip install httpcore

There are also a number of optional extras available...

$ pip install httpcore['asyncio,trio,http2,socks']

Sending requests

Send an HTTP request:

import httpcore

response = httpcore.request("GET", "https://www.example.com/")

print(response)
# <Response [200]>
print(response.status)
# 200
print(response.headers)
# [(b'Accept-Ranges', b'bytes'), (b'Age', b'557328'), (b'Cache-Control', b'max-age=604800'), ...]
print(response.content)
# b'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>\n\n<meta charset="utf-8"/>\n ...'

The top-level httpcore.request() function is provided for convenience. In practice whenever you're working with httpcore you'll want to use the connection pooling functionality that it provides.

import httpcore

http = httpcore.ConnectionPool()
response = http.request("GET", "https://www.example.com/")

Once you're ready to get going, head over to the documentation.

Motivation

You probably don't want to be using HTTP Core directly. It might make sense if you're writing something like a proxy service in Python, and you just want something at the lowest possible level, but more typically you'll want to use a higher level client library, such as httpx.

The motivation for httpcore is:

  • To provide a reusable low-level client library, that other packages can then build on top of.
  • To provide a really clear interface split between the networking code and client logic, so that each is easier to understand and reason about in isolation.

Dependencies

The httpcore package has the following dependencies...

  • h11
  • certifi

And the following optional extras...

  • anyio - Required by pip install httpcore['asyncio'].
  • trio - Required by pip install httpcore['trio'].
  • h2 - Required by pip install httpcore['http2'].
  • socksio - Required by pip install httpcore['socks'].

Versioning

We use SEMVER for our versioning policy.

For changes between package versions please see our project changelog.

We recommend pinning your requirements either the most current major version, or a more specific version range:

pip install 'httpcore==1.*'

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog.

Version 1.0.9 (April 24th, 2025)

Version 1.0.8 (April 11th, 2025)

  • Fix AttributeError when importing on Python 3.14. (#1005)

Version 1.0.7 (November 15th, 2024)

  • Support proxy=… configuration on ConnectionPool(). (#974)

Version 1.0.6 (October 1st, 2024)

  • Relax trio dependency pinning. (#956)
  • Handle trio raising NotImplementedError on unsupported platforms. (#955)
  • Handle mapping ssl.SSLError to httpcore.ConnectError. (#918)

1.0.5 (March 27th, 2024)

  • Handle EndOfStream exception for anyio backend. (#899)
  • Allow trio 0.25.* series in package dependancies. (#903)

1.0.4 (February 21st, 2024)

  • Add target request extension. (#888)
  • Fix support for connection Upgrade and CONNECT when some data in the stream has been read. (#882)

1.0.3 (February 13th, 2024)

  • Fix support for async cancellations. (#880)
  • Fix trace extension when used with socks proxy. (#849)
  • Fix SSL context for connections using the "wss" scheme (#869)

1.0.2 (November 10th, 2023)

  • Fix float("inf") timeouts in Event.wait function. (#846)

1.0.1 (November 3rd, 2023)

  • Fix pool timeout to account for the total time spent retrying. (#823)
  • Raise a neater RuntimeError when the correct async deps are not installed. (#826)
  • Add support for synchronous TLS-in-TLS streams. (#840)

1.0.0 (October 6th, 2023)

From version 1.0 our async support is now optional, as the package has minimal dependencies by default.

For async support use either pip install 'httpcore[asyncio]' or pip install 'httpcore[trio]'.

The project versioning policy is now explicitly governed by SEMVER. See https://semver.org/.

  • Async support becomes fully optional. (#809)
  • Add support for Python 3.12. (#807)

0.18.0 (September 8th, 2023)

  • Add support for HTTPS proxies. (#745, #786)
  • Drop Python 3.7 support. (#727)
  • Handle sni_hostname extension with SOCKS proxy. (#774)
  • Handle HTTP/1.1 half-closed connections gracefully. (#641)
  • Change the type of Extensions from Mapping[Str, Any] to MutableMapping[Str, Any]. (#762)

0.17.3 (July 5th, 2023)

  • Support async cancellations, ensuring that the connection pool is left in a clean state when cancellations occur. (#726)
  • The networking backend interface has been added to the public API. Some classes which were previously private implementation detail are now part of the top-level public API. (#699)
  • Graceful handling of HTTP/2 GoAway frames, with requests being transparently retried on a new connection. (#730)
  • Add exceptions when a synchronous trace callback is passed to an asynchronous request or an asynchronous trace callback is passed to a synchronous request. (#717)
  • Drop Python 3.7 support. (#727)

0.17.2 (May 23th, 2023)

  • Add socket_options argument to ConnectionPool and HTTProxy classes. (#668)
  • Improve logging with per-module logger names. (#690)
  • Add sni_hostname request extension. (#696)
  • Resolve race condition during import of anyio package. (#692)
  • Enable TCP_NODELAY for all synchronous sockets. (#651)

0.17.1 (May 17th, 2023)

  • If 'retries' is set, then allow retries if an SSL handshake error occurs. (#669)
  • Improve correctness of tracebacks on network exceptions, by raising properly chained exceptions. (#678)
  • Prevent connection-hanging behaviour when HTTP/2 connections are closed by a server-sent 'GoAway' frame. (#679)
  • Fix edge-case exception when removing requests from the connection pool. (#680)
  • Fix pool timeout edge-case. (#688)

0.17.0 (March 16th, 2023)

  • Add DEBUG level logging. (#648)
  • Respect HTTP/2 max concurrent streams when settings updates are sent by server. (#652)
  • Increase the allowable HTTP header size to 100kB. (#647)
  • Add retries option to SOCKS proxy classes. (#643)

0.16.3 (December 20th, 2022)

  • Allow ws and wss schemes. Allows us to properly support websocket upgrade connections. (#625)
  • Forwarding HTTP proxies use a connection-per-remote-host. Required by some proxy implementations. (#637)
  • Don't raise RuntimeError when closing a connection pool with active connections. Removes some error cases when cancellations are used. (#631)
  • Lazy import anyio, so that it's no longer a hard dependancy, and isn't imported if unused. (#639)

0.16.2 (November 25th, 2022)

  • Revert 'Fix async cancellation behaviour', which introduced race conditions. (#627)
  • Raise RuntimeError if attempting to us UNIX domain sockets on Windows. (#619)

0.16.1 (November 17th, 2022)

  • Fix HTTP/1.1 interim informational responses, such as "100 Continue". (#605)

0.16.0 (October 11th, 2022)

  • Support HTTP/1.1 informational responses. (#581)
  • Fix async cancellation behaviour. (#580)
  • Support h11 0.14. (#579)

0.15.0 (May 17th, 2022)

  • Drop Python 3.6 support (#535)
  • Ensure HTTP proxy CONNECT requests include timeout configuration. (#506)
  • Switch to explicit typing.Optional for type hints. (#513)
  • For trio map OSError exceptions to ConnectError. (#543)

0.14.7 (February 4th, 2022)

  • Requests which raise a PoolTimeout need to be removed from the pool queue. (#502)
  • Fix AttributeError that happened when Socks5Connection were terminated. (#501)

0.14.6 (February 1st, 2022)

  • Fix SOCKS support for http:// URLs. (#492)
  • Resolve race condition around exceptions during streaming a response. (#491)

0.14.5 (January 18th, 2022)

  • SOCKS proxy support. (#478)
  • Add proxy_auth argument to HTTPProxy. (#481)
  • Improve error message on 'RemoteProtocolError' exception when server disconnects without sending a response. (#479)

0.14.4 (January 5th, 2022)

  • Support HTTP/2 on HTTPS tunnelling proxies. (#468)
  • Fix proxy headers missing on HTTP forwarding. (#456)
  • Only instantiate SSL context if required. (#457)
  • More robust HTTP/2 handling. (#253, #439, #440, #441)

0.14.3 (November 17th, 2021)

  • Fix race condition when removing closed connections from the pool. (#437)

0.14.2 (November 16th, 2021)

  • Failed connections no longer remain in the pool. (Pull #433)

0.14.1 (November 12th, 2021)

  • max_connections becomes optional. (Pull #429)
  • certifi is now included in the install dependancies. (Pull #428)
  • h2 is now strictly optional. (Pull #428)

0.14.0 (November 11th, 2021)

The 0.14 release is a compl