Coder Social home page Coder Social logo

httplib2shim's Introduction

httplib2shim

Build Status Coverage Status PyPI Version

httplib2shim is a wrapper over httplib2 that uses urllib3 to perform HTTP requests. This library is intended to help existing legacy libraries (and their users) to migrate away from httplib2. It is not intended to be a general purpose replacement for httplib2. It does not support every feature and edge case for httplib2, although contributions are welcome in order to help us cover these cases.

Presently, httplib2shim passes the test suite for httplib2. A few non-applicable tests were disabled, and it's very possible that the tests do not account for behavior that is depended on by clients.

Usage

It's recommended to install urllib3[secure] before installing httplib2shim:

pip install urllib3[secure] httplib2shim

Usage is straightforward. You can substitute httplib2shim.Http anywhere httplib2.Http is used. E.g. for the oauth2client use:

import httplib2shim
from oauth2client.client import GoogleCredentials


credentials = GoogleCredentials.get_application_default()
http = httplib2shim.Http()
credentials.authorize(http)

# http is now authorized with OAuth2 credentials and uses urllib3 under
# the covers.

and for the google-auth use:

import httplib2shim
import google.auth
import google_auth_httplib2

credentials, _ = google.auth.default()
http = httplib2shim.Http()
http = google_auth_httplib2.AuthorizedHttp(credentials, http=http)

Alternatively, if you do not control the construction of the Http object, you can use httplib2shim.patch() to monkey-patch the httplib2.Http class to point to httplib2shim.Http():

import httplib2shim
httplib2shim.patch()

from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

# build constructs its own httplib2.Http instance.
service = build('compute', 'v1', credentials=credentials)

# service.http is now a httplib2shim.Http object.

Unsupported Features

  • Arguments to the Http constructor will be accepted, but may not make a difference. For instance, ca_certs will have no effect. Instead, pass a urllib3.Pool instance http = httplib2shim.Http(pool=my_pool).
  • Http.add_certificate is a no-op and will warn.
  • Probably others, pull requests are welcome to complete the functionality.

Contributing changes

Licensing

httplib2shim's People

Contributors

xmedeko avatar cwt avatar halvards avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.