Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A minimal HTTP client. ⚙️

License

NotificationsYou must be signed in to change notification settings

encode/httpcore

Test SuitePackage version

Do one thing, and do it well.

The HTTP Core package provides a minimal low-level HTTP client, which doesone 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 configurationdefaults, 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 forasyncio andtrio.

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:

importhttpcoreresponse=httpcore.request("GET","https://www.example.com/")print(response)# <Response [200]>print(response.status)# 200print(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-levelhttpcore.request() function is provided for convenience. In practice whenever you're working withhttpcore you'll want to use the connection pooling functionality that it provides.

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

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

Motivation

Youprobably don't want to be using HTTP Core directly. It might make sense ifyou're writing something like a proxy service in Python, and you just wantsomething at the lowest possible level, but more typically you'll want to usea higher level client library, such ashttpx.

The motivation forhttpcore is:

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

Dependencies

Thehttpcore package has the following dependencies...

  • h11
  • certifi

And the following optional extras...

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

Versioning

We useSEMVER for our versioning policy.

For changes between package versions please see ourproject changelog.

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

pipinstall'httpcore==1.*'

[8]ページ先頭

©2009-2025 Movatter.jp