HTTPX: Help Build The Future Of Python HTTP
Tags: hacktoberfest, python, webdev
Published: 2019-10-02 11:47:37

{% github https://github.com/encode/httpx %}

HTTPX 🦋 is a next generation HTTP client for Python. It is [Requests](https://requests.kennethreitz.org)-compatible, supports HTTP/2 and HTTP/1.1, has async support, and an ever-expanding community of 35+ awesome contributors. ❤

> HTTPX is part of a growing ecosystem of async-capable Python projects lead by the [Encode](https://github.com/encode/) organization (which backs the [Django REST Framework](https://www.django-rest-framework.org/)). Some of the most notable projects include [Uvicorn](https://www.uvicorn.org/), [Starlette](https://www.starlette.io/), and [Databases](https://www.encode.io/databases/).

[Hacktoberfest](https://hacktoberfest.digitalocean.com/) started yesterday, and on behalf of the HTTPX maintenance team I can say we're very excited to be part of it this year!

Before getting to the contributing guide, a short preview of what HTTPX can do…

Your first request to dev.to using HTTPX:

```python
>>> import httpx
>>> r = httpx.get('https://dev.to')
>>> r.status_code
200
>>> r.headers['content-type']
'text/html; charset=utf-8'
>>> r.text[:50]
'<!DOCTYPE html>\n<html lang="en">\n  <head>\n    <met'
>>> r.http_version
'HTTP/1.1'
```

Does DEV support HTTP/2?

```python
>>> import httpx
>>> # The top-level API only supports HTTP/1.1 for efficiency reasons,
>>> # but 'Client' uses HTTP/2 by default.
>>> with httpx.Client() as client:
...    r = client.get('https://dev.to')
...
>>> r.http_version
'HTTP/2'  # YAY! 🎉
```

HTTPX can even call into Python web apps (WSGI + ASGI). A Flask example…

```python
>>> from flask import Flask
>>> import httpx
>>> app = Flask(__name__)
>>> @app.route("/")
... def hello():
...     return "Hello, world"
...
>>> with httpx.Client(app=app, base_url='http://testserver') as client:
...     r = client.get('/')
...
>>> r.status_code
200
>>> r.text
'Hello, world'  # Tada! 🦋
>>>
```

And it supports `async/await`! Let's fire an IPython REPL to try this out:

```python
In [1]: import httpx
In [2]: import asyncio
In [3]: # We're going to fetch tag pages concurrently...
In [4]: async def fetch(tag, client):
   ...:     return await client.get(f'https://dev.to/t/{tag}')
   ...:

In [5]: async with httpx.AsyncClient() as client:
   ...:     responses = await asyncio.gather(
   ...:         fetch('hacktoberfest', client),
   ...:         fetch('python', client),
   ...:         fetch('opensource' client),
   ...:     )

In [6]: responses
Out[6]: [<Response [200 OK]>, <Response [200 OK]>, <Response [200 OK]>]
In [7]: [r.url for r in responses]
Out[7]:
[URL('https://dev.to/t/hacktoberfest'),
 URL('https://dev.to/t/python'),
 URL('https://dev.to/t/opensource')]
```

(This example uses `asyncio`,  but [`trio` is also supported](https://www.encode.io/httpx/async/#trio)!)

HTTPX already has a lot of features built-in, but it's still in an alpha stage as some of the areas still need more work.

So enough of an intro, here's how YOU can help us build the future of Python HTTP.

## How you can help

### Try it out!

The most straight-forward way to help move HTTPX forward is by **trying it out** for yourself.

For example:

- Run the sample code in the introduction to this post to see HTTPX in action!
- Build a simple application that calls a [public API](https://github.com/public-apis/public-apis) using HTTPX.
- Migrate an application that uses Requests to make HTTP calls over to HTTPX.
- Use HTTPX as a test client for your web project powered by Flask, Starlette, FastAPI, etc. More on this in [Calling into Python web apps](https://www.encode.io/httpx/advanced/#calling-into-python-web-apps).
- Build a web spider that fetches web pages in parallel using HTTPX.
- ... And any other idea you feel like trying!

However you decide to try HTTPX out, we'd love to hear about it! Send us a link to a repo, blog post, or anything else you'd like to share via the comments section. :-)

### Contribute!

As of writing this post, there's a whopping list of [10 `hacktoberfest`-labelled issues](https://github.com/encode/httpx/issues?q=is%3Aissue+is%3Aopen+label%3Ahacktoberfest), all up for grabs! Expect more to come!

Below are some highlights of what's available at the moment.

#### Documentation

Documentation is critical to any software project. It helps new users get started quickly, and existing users find the information they need on how to use a particular feature or piece of API.

We know that the [HTTPX documentation](https://encode.io/httpx) needs refining in several places. Feel free to walk through it and submit PRs for anything you think can be improved — be it typos, copy, or missing information. :-)

{% github https://github.com/encode/httpx/issues/409 %}

{% github https://github.com/encode/httpx/issues/404 %}

{% github https://github.com/encode/httpx/issues/403 %}

### Bug fixes

Fact: all software has bugs 🐛, and surely HTTPX is no different!

Some of the bugs have already been tracked…

{% github https://github.com/encode/httpx/issues/391 %}

…But most of them still need to be discovered, tracked down, and fixed!

This is also why it's super important that you **give HTTPX a try**. Your use case may not be one we have thought about yet, or it might be in conditions that haven't be accounted for yet.

If you find about something that doesn't look right, please [open an issue](https://github.com/encode/httpx/issues/new) and we'll look into it together!

### New features

HTTPX already has a lot of features built-in, but we've got ideas on how to push things even further.

Below are some features you can tackle. If you try out HTTPX and feel like something's missing, please [open an issue](https://github.com/encode/httpx/issues/new)! We'll discuss it together and will gladly help you get started if you'd like to implement the feature.

{% github https://github.com/encode/httpx/issues/360 %}

{% github https://github.com/encode/httpx/issues/349 %}

## Closing thoughts

There are many ways to contribute to HTTPX, and all contributions are welcome! Once you've selected an issue, documentation improvement, feature request or bug report you'd like to work on, read the [contributing guide](https://www.encode.io/httpx/contributing/) to get started, and hack away!

Thank you so much for reading through this post, and we look forward to seeing the amazing contributions you'll make. 💖🦋

— The HTTPX maintenance team