DEV Community

qing
qing

Posted on • Edited on

Quick Tip: `httpx` is the modern replacement for `requests`

Quick Tip: httpx is the modern replacement for requests

When it comes to making HTTP requests in Python, requests has been the go-to library for years. However, with the introduction of httpx, it's time to upgrade. httpx is a modern, Pythonic library that supports both synchronous and asynchronous requests.

Let's compare a simple GET request using requests and httpx:


python
# requests (sync)
import requests
response = requests.get('https://example.com')

# httpx (async)
import httpx
import asyncio
async def main():
    async with httpx.AsyncClient() as client:
        response = await client.get('https://example.com')
asyncio

---

*Follow me on Dev.to for daily Python tips and quick guides!*

---

## 🔗 Recommended Resources

- [Python Crash Course](https://www.amazon.com/Python-Crash-Course-2nd-Edition/dp/1593279280?tag=automoney-20) — *3-10%*

*Note: Some links are affiliate links. Using them supports this blog at no extra cost to you.*
Enter fullscreen mode Exit fullscreen mode

Top comments (0)