Top Related Projects
Quick Overview
Hyper is a Python HTTP/2 client library. It provides a low-level interface for making HTTP/2 requests and handling responses, as well as a high-level API that mimics the popular requests
library but with HTTP/2 support.
Pros
- Native HTTP/2 support, allowing for faster and more efficient web requests
- Compatibility with the
requests
library API, making it easy for developers to transition - Support for both synchronous and asynchronous programming models
- Actively maintained and regularly updated
Cons
- Limited to HTTP/2 only, not suitable for projects requiring HTTP/1.1 support
- Smaller community and ecosystem compared to more established HTTP libraries
- May have a steeper learning curve for developers new to HTTP/2 concepts
- Some features still in development or not as mature as in other libraries
Code Examples
- Making a simple GET request:
from hyper import HTTP20Connection
conn = HTTP20Connection('nghttp2.org')
conn.request('GET', '/httpbin/get')
resp = conn.get_response()
print(resp.status)
print(resp.read())
- Using the requests-like API:
from hyper import HTTPConnection
conn = HTTPConnection('nghttp2.org')
resp = conn.request('GET', '/httpbin/get')
print(resp.status_code)
print(resp.json())
- Asynchronous request using asyncio:
import asyncio
from hyper.contrib import HTTP20Adapter
import requests
async def fetch(url):
session = requests.Session()
session.mount('https://', HTTP20Adapter())
response = await session.get(url)
return response.json()
async def main():
result = await fetch('https://nghttp2.org/httpbin/get')
print(result)
asyncio.run(main())
Getting Started
To get started with Hyper, first install it using pip:
pip install hyper
Then, you can make HTTP/2 requests like this:
from hyper import HTTP20Connection
conn = HTTP20Connection('nghttp2.org')
conn.request('GET', '/httpbin/get')
resp = conn.get_response()
print(resp.status)
print(resp.read())
For more advanced usage and configuration options, refer to the official documentation.
Competitor Comparisons
A next generation HTTP client for Python. 🦋
Pros of httpx
- More active development and maintenance
- Supports both sync and async APIs
- Extensive feature set including HTTP/2 and WebSocket support
Cons of httpx
- Larger dependency footprint
- Slightly steeper learning curve for beginners
Code Comparison
httpx:
import httpx
with httpx.Client() as client:
response = client.get('https://example.com')
print(response.text)
hyper:
from hyper import HTTPConnection
conn = HTTPConnection('example.com:443')
conn.request('GET', '/')
resp = conn.get_response()
print(resp.read())
Key Differences
- httpx provides a more user-friendly API, similar to the popular
requests
library - hyper focuses specifically on HTTP/2 implementation, while httpx offers broader protocol support
- httpx has better documentation and a larger community, making it easier to find help and resources
Use Cases
- Choose httpx for general-purpose HTTP client needs, especially if you require both sync and async options
- Consider hyper if you need a lightweight, HTTP/2-focused solution and are comfortable with a lower-level API
Community and Ecosystem
httpx has gained significant traction and is often recommended as a modern alternative to the requests
library, while hyper remains a more specialized tool for HTTP/2 implementations.
urllib3 is a user-friendly HTTP client library for Python
Pros of urllib3
- Widely adopted and battle-tested in production environments
- Extensive feature set, including connection pooling and retry mechanisms
- Compatible with both Python 2 and 3
Cons of urllib3
- Lacks native HTTP/2 support
- Slower performance compared to hyper for certain use cases
- More complex API for advanced features
Code Comparison
urllib3:
import urllib3
http = urllib3.PoolManager()
r = http.request('GET', 'http://example.com')
print(r.status)
print(r.data)
hyper:
from hyper import HTTPConnection
conn = HTTPConnection('http://example.com')
conn.request('GET', '/')
resp = conn.get_response()
print(resp.status)
print(resp.read())
Key Differences
- hyper focuses on HTTP/2 support, while urllib3 primarily targets HTTP/1.1
- urllib3 offers more built-in features like connection pooling and retries
- hyper provides a simpler API for basic HTTP requests
- urllib3 has broader compatibility across Python versions
- hyper may offer better performance for HTTP/2 connections
Both libraries have their strengths, with urllib3 being more versatile and widely used, while hyper excels in HTTP/2 scenarios and offers a streamlined API for simple use cases.
A simple, yet elegant, HTTP library.
Pros of Requests
- Widely adopted and battle-tested in production environments
- Extensive documentation and large community support
- Simple and intuitive API for making HTTP requests
Cons of Requests
- Lacks native support for HTTP/2
- Not as performant for high-concurrency scenarios
- Limited support for advanced features like server push
Code Comparison
Requests:
import requests
response = requests.get('https://api.example.com/data')
print(response.json())
Hyper:
from hyper import HTTPConnection
conn = HTTPConnection('api.example.com:443')
conn.request('GET', '/data')
resp = conn.get_response()
print(resp.read())
Hyper focuses on providing HTTP/2 support, offering improved performance for certain use cases. It's designed for developers who need more control over low-level HTTP operations. Requests, on the other hand, offers a higher-level abstraction that's easier to use for common HTTP tasks.
While Requests is more popular and has a larger ecosystem, Hyper is better suited for applications that require HTTP/2 features or need to handle a large number of concurrent connections efficiently.
Asynchronous HTTP client/server framework for asyncio and Python
Pros of aiohttp
- More mature and widely adopted project with a larger community
- Supports both client and server-side HTTP functionality
- Extensive documentation and examples available
Cons of aiohttp
- Slightly more complex API compared to hyper
- Larger codebase, which may lead to longer startup times
Code Comparison
aiohttp client example:
async with aiohttp.ClientSession() as session:
async with session.get('http://example.com') as response:
html = await response.text()
print(html)
hyper client example:
with HTTP20Connection('http2bin.org') as conn:
response = conn.request('GET', '/get')
print(response.read())
Key Differences
- aiohttp uses asyncio for asynchronous operations, while hyper focuses on HTTP/2 support
- hyper is more lightweight and specifically designed for HTTP/2, while aiohttp offers broader HTTP functionality
- aiohttp provides both client and server capabilities, whereas hyper is primarily client-focused
Use Cases
- Choose aiohttp for general-purpose async HTTP client/server needs in Python
- Opt for hyper when working specifically with HTTP/2 or requiring a lightweight HTTP client
Both libraries have their strengths, and the choice depends on your specific project requirements and preferences.
Requests + Gevent = <3
Pros of grequests
- Simpler API, easier to use for basic concurrent requests
- Built on top of the popular
requests
library, familiar to many Python developers - Lightweight and focused on asynchronous HTTP requests
Cons of grequests
- Less feature-rich compared to Hyper's HTTP/2 support
- Not actively maintained, with fewer recent updates
- Limited to HTTP/1.1 protocol
Code Comparison
grequests:
import grequests
urls = ['http://example.com', 'http://example.org']
rs = (grequests.get(u) for u in urls)
responses = grequests.map(rs)
Hyper:
from hyper import HTTPConnection
conn = HTTPConnection('example.com:443')
conn.request('GET', '/')
resp = conn.get_response()
Summary
grequests offers a simpler API for concurrent HTTP requests, built on the widely-used requests
library. It's lightweight and easy to use for basic asynchronous operations. However, it lacks advanced features like HTTP/2 support, which Hyper provides. Hyper is more actively maintained and offers a more comprehensive set of HTTP-related features, including HTTP/2 capabilities. The choice between the two depends on the specific requirements of your project, with grequests being suitable for simpler concurrent HTTP/1.1 requests and Hyper being more appropriate for advanced HTTP/2 implementations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
=============================== Hyper: HTTP/2 Client for Python
This project is no longer maintained!
Please use an alternative, such as HTTPX
_ or others.
.. _HTTPX: https://www.python-httpx.org/
We will not publish further updates for hyper
.
Potential security issues will not be addressed.
So long, and thanks for all the fish!
.. image:: https://raw.github.com/Lukasa/hyper/development/docs/source/images/hyper.png
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.
hyper
provides these benefits to your Python code. How? Like this::
from hyper import HTTPConnection
conn = HTTPConnection('nghttp2.org:443')
conn.request('GET', '/httpbin/get')
resp = conn.get_response()
print(resp.read())
Simple.
Caveat Emptor!
Please be warned: hyper
is in a very early alpha. You will encounter bugs
when using it. In addition, there are very many rough edges. With that said,
please try it out in your applications: I need your feedback to fix the bugs
and file down the rough edges.
Versions
hyper
supports the final draft of the HTTP/2 specification: additionally,
it provides support for drafts 14, 15, and 16 of the HTTP/2 specification. It
also supports the final draft of the HPACK specification.
Compatibility
hyper
is intended to be a drop-in replacement for http.client
, with a
similar API. However, hyper
intentionally does not name its classes the
same way http.client
does. This is because most servers do not support
HTTP/2 at this time: I don't want you accidentally using hyper
when you
wanted http.client
.
Documentation
Looking to learn more? Documentation for hyper
can be found on Read the Docs
_.
.. _Read the Docs: http://hyper.readthedocs.io/en/latest/
Contributing
hyper
welcomes contributions from anyone! Unlike many other projects we are
happy to accept cosmetic contributions and small contributions, in addition to
large feature requests and changes.
Before you contribute (either by opening an issue or filing a pull request),
please read the contribution guidelines
_.
.. _read the contribution guidelines: http://hyper.readthedocs.org/en/development/contributing.html
License
hyper
is made available under the MIT License. For more details, see the
LICENSE
file in the repository.
Authors
hyper
is maintained by Cory Benfield, with contributions from others. For
more details about the contributors, please see CONTRIBUTORS.rst
.
Top Related Projects
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot