What Python libraries support HTTP2?

Python has many different HTTP clients that can be used for web scraping. However, not all of them support HTTP2 which can be vital in avoiding web scraper blocking.

Here are the most popular HTTP clients that support HTTP2:

  • HTTPX - is one of the most popular new libraries for Python. HTTPX supports HTTP2 as well as asyncio making it great for web scraping:
import httpx
with httpx.Client(http2=True) as client:
    response = client.get("https://httpbin.dev/anything")
  • h2 is a low-level implementation of HTTP2 protocol. It's not recommended to use it directly for web scraping but it can be the only way to implement complex HTTP2 interactions for niche web scrapers.
  import h2.connection
  import h2.config

  config = h2.config.H2Configuration()
  conn = h2.connection.H2Connection(config=config)
  conn.send_headers(stream_id=stream_id, headers=headers)
  conn.send_data(stream_id, data)
  events = conn.receive_data(socket_data)

So, it's best to stick to httpx for HTTP2 though if you have a complex use case h2 can be adapted to extendible libraries like twisted.

How to Web Scrape with HTTPX and Python

For more on HTTPX in web scraping see our hands-on introduction article which covers everything you need to know when it comes to web scraping

How to Web Scrape with HTTPX and Python
Question tagged: Python, HTTP

Related Posts

How to Scrape Reddit Posts, Subreddits and Profiles

In this article, we'll explore how to scrape Reddit. We'll extract various social data types from subreddits, posts, and user pages. All of which through plain HTTP requests without headless browser usage.

How to Scrape With Headless Firefox

Discover how to use headless Firefox with Selenium, Playwright, and Puppeteer for web scraping, including practical examples for each library.

How to Scrape LinkedIn.com Profile, Company, and Job Data

In this scrape guide we'll be taking a look at one of the most popular web scraping targets - LinkedIn.com. We'll be scraping people profiles, company profiles as well as job listings and search.