Hyper 简介: HTTP/2 Client for Python

简介

官方原文
HTTP is changing under our feet. HTTP/1.1, our old friend, is being supplemented by the brand new HTTP/2 standard. HTTP/2 provides many benefits: improved speed, lower bandwidth usage, better connection management, and more.

特性

Simple. hyper is written in 100% pure Python, which means no C extensions. For recent versions of Python (3.4 and onward, and 2.7.9 and onward) it’s entirely self-contained with no external dependencies.
hyper supports Python 3.4 and Python 2.7.9, and can speak HTTP/2 and HTTP/1.1.

hyper 简单,使用 100% 的纯 Python 编写,这意味着没有 C 扩展。对于最近的 Python 版本(3.4 和更新,2.7.9 和更新),它是完全的自包含,并没有其他的依赖。
hyper 支持 Python 3.4 和 Python 2.7.9, 并且可以表达 HTTP/2 和 HTTP/1.1.

安装

pip install hyper

demo

http://hyper.readthedocs.io/en/latest/index.html

from hyper import HTTPConnection

conn = HTTPConnection('http2bin.org:443')
conn.request('GET', '/get')
resp = conn.get_response()

print(resp.read())

HTTP/2 demo

文档:http://hyper.readthedocs.io/en/latest/api.html#http-2

conn = HTTP20Connection(host=base_url, secure=True)
response = conn.request(method,url)
resp = conn.get_response(response)
print (resp.status)
print (resp.read())

issue

并没有相关返回值可以直接查看 HTTP 版本,已经向开发者反馈。开发者建议的方案是 type 一下返回的 response,更为简洁的方案还在开发中。

https://github.com/Lukasa/hyper/issues/285

使用体验

Hyper 和一般的 HTTP Client 相比,感觉还比较麻烦,不够完善。不过是 Python HTTP Client 中比较好的。文档中关于 HTTP/2 的内容比较少,也没有提供太多的 demo 。相比较 Python 的另外一个库 requests 学习成本会高一些。

引用

https://github.com/Lukasa/hyper
http://hyper.readthedocs.io/en/latest/

    原文作者:不知道自己是谁
    原文地址: https://www.jianshu.com/p/35cc597d53c3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞