• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

encode/httpcore: A minimal HTTP client. ⚙️

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

encode/httpcore

开源软件地址:

https://github.com/encode/httpcore

开源编程语言:

Python 99.2%

开源软件介绍:

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.7+

Installation

For HTTP/1.1 only support, install with:

$ pip install httpcore

For HTTP/1.1 and HTTP/2 support, install with:

$ pip install httpcore[http2]

For SOCKS proxy support, install with:

$ pip install httpcore[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.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap