Contrib Modules

These modules implement various extra features, that may not be ready for prime time.

SNI-support for Python 2

Module for using pyOpenSSL as a TLS backend. This module was relevant before the standard library ssl module supported SNI, but now that we’ve dropped support for Python 2.7 all relevant Python versions support SNI so this module is no longer recommended.

This needs the following packages installed:

However, pyOpenSSL depends on cryptography, which depends on idna, so while we use all three directly here we end up having relatively few packages required.

You can install them with the following command:

$ python -m pip install pyopenssl cryptography idna

To activate certificate checking, call inject_into_urllib3() from your Python code before you begin making HTTP requests. This can be done in a sitecustomize module, or at any other time before your application begins using urllib3, like this:

try:
    import urllib3.contrib.pyopenssl
    urllib3.contrib.pyopenssl.inject_into_urllib3()
except ImportError:
    pass

Google App Engine

The urllib3.contrib.appengine module provides a pool manager that uses Google App Engine’s URLFetch Service.

Example usage:

from urllib3 import PoolManager
from urllib3.contrib.appengine import AppEngineManager, is_appengine_sandbox

# This substitution will be done automagically once appengine code
# graduates from the contrib module.
if is_appengine_sandbox():
    # AppEngineManager uses AppEngine's URLFetch API behind the scenes
    http = AppEngineManager()
else:
    # PoolManager uses a socket-level API behind the scenes
    http = PoolManager()

# The client API should be consistent across managers, though some features are not available
# in URLFetch and you'll get warnings when you try to use them (like granular timeouts).
r = http.request('GET', 'https://google.com/')

There are limitations to the URLFetch service and it may not be the best choice for your application. App Engine provides three options for urllib3 users:

  1. You can use AppEngineManager with URLFetch. URLFetch is cost-effective in many circumstances as long as your usage is within the limitations.

  2. You can use a normal PoolManager by enabling sockets. Sockets also have limitations and restrictions and have a lower free quota than URLFetch. To use sockets, be sure to specify the following in your app.yaml:

    env_variables:
        GAE_USE_SOCKETS_HTTPLIB : 'true'
    
  3. If you are using Managed VMs, you can use the standard PoolManager without any configuration or special environment variables.