httpx README

The project's README from github.com/encode/httpx. As one markdown file: README.md.

HTTPX

HTTPX - A next-generation HTTP client for Python.

Test Suite Package version

HTTPX is a fully featured HTTP client library for Python 3. It includes an integrated command line client, has support for both HTTP/1.1 and HTTP/2, and provides both sync and async APIs.


Install HTTPX using pip:

$ pip install httpx

Now, let's get started:

>>> import httpx
>>> r = httpx.get('https://www.example.org/')
>>> r
<Response [200 OK]>
>>> r.status_code
200
>>> r.headers['content-type']
'text/html; charset=UTF-8'
>>> r.text
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'

Or, using the command-line client.

$ pip install 'httpx[cli]'  # The command line client is an optional dependency.

Which now allows us to use HTTPX directly from the command-line...

httpx --help

Sending a request...

httpx http://httpbin.org/json

Features

HTTPX builds on the well-established usability of requests, and gives you:

Plus all the standard features of requests...

Installation

Install with pip:

$ pip install httpx

Or, to include the optional HTTP/2 support, use:

$ pip install httpx[http2]

HTTPX requires Python 3.9+.

Documentation

Project documentation is available at https://www.python-httpx.org/.

For a run-through of all the basics, head over to the QuickStart.

For more advanced topics, see the Advanced Usage section, the async support section, or the HTTP/2 section.

The Developer Interface provides a comprehensive API reference.

To find out about tools that integrate with HTTPX, see Third Party Packages.

Contribute

If you want to contribute with HTTPX check out the Contributing Guide to learn how to start.

Dependencies

The HTTPX project relies on these excellent libraries:

As well as these optional installs:

A huge amount of credit is due to requests for the API layout that much of this work follows, as well as to urllib3 for plenty of design inspiration around the lower-level networking details.


HTTPX is BSD licensed code.
Designed & crafted with care.

— 🦋 —

httpx (encode/httpx)

Searching Database…

15.6K ·GitHub
这是做什么用的?HTTPX 是一个功能齐全的 Python 3 HTTP 客户端库,它的 API 与 requests 大体兼容,支持 HTTP/1.1 和 HTTP/2,同时提供同步和异步两种接口。它还自带一个集成的命令行客户端。
它是库还是命令行工具?主要是一个在代码里导入使用的 Python 库,不过同一个项目也附带了一个集成的命令行客户端,所以不用写脚本就能直接在终端里发请求。
使用之前需要装好什么?需要 Python 3.9 或更新版本。核心依赖(httpcore、h11、certifi、idna、sniffio)会由 pip 自动安装,所以除了 Python 本身之外不需要再配置什么。
HTTP/2 是开箱即用的吗?不是。HTTP/2 需要通过可选的额外组件来启用:pip install httpx[http2]。不装的话用的就是 HTTP/1.1,对大多数 API 和日常请求来说也够用了。
为什么选 httpx 而不是 requests?它沿用了大家熟悉的 requests 风格的 API,同时增加了 HTTP/1.1 和 HTTP/2 支持、异步、直接调用 WSGI/ASGI 应用,以及处处严格的超时控制——README 甚至明确感谢了 requests,说自己沿袭了它的 API 设计。
能不能不用启动服务器就测试我的 Web 应用?可以。httpx 能把请求直接发给 WSGI 和 ASGI 应用,也就是在进程内直接跑一个应用,这在写测试时很方便。
命令行客户端能做什么?安装 httpx[cli] 这个额外组件后,你可以直接在终端里发 HTTP 请求,终端输出由 rich 这个库渲染,效果很丰富。
它成熟到可以用于生产环境吗?整个代码库都有完整的类型标注和 100% 的测试覆盖率,底层的网络部分则交给了 httpcore、h11 这类久经考验的库来处理。
Creator
encode
Size
8.4 MB
Stars
15.6K
Age
7y
Commits · 90 Days