DEV Community

Cover image for urllib4-enhanced Lib
Zied
Zied

Posted on

urllib4-enhanced Lib

urllib4: The Next Generation HTTP Client for Python

Introduction

I'm excited to share a new Python HTTP client library called urllib4-enhanced. This library builds upon the foundation of urllib3 while adding powerful features for modern web applications. If you're working with HTTP in Python, this might be the upgrade you've been looking for.

What is urllib4?

urllib4 is a modern HTTP client for Python that extends the capabilities of urllib3 with advanced features designed for today's web ecosystem. It maintains the familiar API that millions of developers already know while adding support for newer protocols and security enhancements.

Key Features

HTTP/2 Support

urllib4 provides comprehensive HTTP/2 support, including:

  • Server Push capabilities
  • Connection pooling optimized for HTTP/2
  • Configurable connection profiles for different performance needs

WebSocket Support

The library includes robust WebSocket implementation with:

  • Compression with permessage-deflate
  • Multiple subprotocols (JSON, MessagePack, CBOR)
  • Connection health monitoring
  • Backpressure handling

HTTP/3 (QUIC) Support

urllib4 is one of the first Python libraries to offer HTTP/3 support:

  • Direct HTTP/3 connections
  • Multipath QUIC for improved reliability
  • 0-RTT connection establishment for faster connections

Enhanced Security Features

Security is a priority with:

  • SPKI pinning
  • Certificate Transparency verification
  • HSTS support
  • Improved TLS configuration

Simple Usage Examples

Basic GET request:

import urllib4
resp = urllib4.request("GET", "http://httpbin.org/robots.txt")
print(resp.status)  # 200
print(resp.data)    # b"User-agent: *\nDisallow: /deny\n"
Enter fullscreen mode Exit fullscreen mode

POST request with JSON:

import urllib4
import json

data = {"name": "John", "age": 30}
resp = urllib4.request(
    "POST",
    "http://httpbin.org/post",
    headers={"Content-Type": "application/json"},
    body=json.dumps(data).encode()
)
Enter fullscreen mode Exit fullscreen mode

Installation

You can install urllib4-enhanced with pip:

pip install urllib4-enhanced
Enter fullscreen mode Exit fullscreen mode

For additional features:

# For HTTP/3 support
pip install urllib4-enhanced[http3]

# For WebSocket subprotocols
pip install urllib4-enhanced[websocket]

# For all optional features
pip install urllib4-enhanced[all]
Enter fullscreen mode Exit fullscreen mode

Why Choose urllib4?

  1. Future-proof: Support for the latest HTTP protocols
  2. Familiar API: Easy migration from urllib3
  3. Performance: Optimized for modern web applications
  4. Security: Enhanced security features out of the box
  5. Flexibility: Optional components for specific needs

Project Status

The project is production-ready and actively maintained. It supports Python 3.7+ and is designed with both backward compatibility and forward-thinking features in mind.

Getting Involved

If you're interested in contributing or have questions:

Conclusion

urllib4 represents the next evolution in Python HTTP clients. Whether you're building a simple script or a complex web application, urllib4 provides the tools you need for modern HTTP communication.

Give it a try and let me know what you think!

Top comments (0)