Code Monkey home page Code Monkey logo

gcloud_requests's Introduction

gcloud_requests

GitHub license PyPI Version Build Status Code Climate PyPI Popularity

Thread-safe client functionality for gcloud-python via requests.

Installation

pip install --upgrade gcloud_requests

Note that at this time, only gcloud==0.17.0 on Python 2.7 is officially supported.

Usage

The library provides new HTTP objects that can be passed in to the gcloud.*.Client constructors (per supported API module). For example, to use the connection class (with proper retrying implemented) for Google Cloud Datastore:

from gcloud import datastore
from gcloud_requests.connection import datastore_http

client = datastore.Client(http=datastore_http)
client.query(kind="EntityKind").fetch()

and for the Google Cloud Storage service:

from gcloud import storage
from gcloud_requests.connection import storage_http

client = storage.Client(http=storage_http, project="my-project")
bucket = client.get_bucket("my-bucket")

Custom credentials

Using a custom HTTP object causes gcloud Clients to ignore whatever Credentials objects you pass into them manually. If you need to use a custom set of credentials with gcloud_requests you must instantiate a RequestsProxy object by passing in those credentials and then passing that instance to your client like so:

from gcloud import datastore
from gcloud_requests.requests_connection import DatastoreRequestsProxy

http = DatastoreRequestsProxy(custom_credentials)
client = datastore.Client(http=http)

Background

The gcloud-python library for accessing Google Cloud Platform services like Google Cloud Datastore, Google Cloud Storage, Google BigQuery, and others, relies on the httplib2 library to handle the underlying Protobuf requests. This library (httplib2) is not threadsafe.

Based on notes in gcloud-python#926, gcloud-python#908, and gcloud-python#1214, this library replaces the underlying transport with requests.

Running Tests

It's strongly encouraged that you let Travis run the tests. This is because running the tests requires gcd, the Google Cloud Datastore tools, which also requires a Google Cloud Platform service key...if you're still intrigued, work through the gcd documentation and then simply install pytest and run the tests with py.test.

Authors

gcloud_requests was authored at Leadpages. You can find out more about contributors here. We welcome contributions, and we're always looking for more engineering talent!

Contributing

Please read our contributor's guide.

gcloud_requests's People

Contributors

bogdanp avatar bendemaree avatar kawa-kokosowa avatar davidan1981 avatar hakshak avatar

Watchers

Alexey Novichenko avatar  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.