Base for Everything¶
To use the API, the Client
class defines a high-level interface which handles authorization
and creating other objects:
from gcloud_bigtable.client import Client
client = Client()
Long-lived Defaults¶
When creating a Client
, the
user_agent
and timeout_seconds
arguments have sensible
defaults
(DEFAULT_USER_AGENT
and
DEFAULT_TIMEOUT_SECONDS
).
However, you may over-ride them and these will be used throughout all API
requests made with the client
you create.
Authorization¶
This will use the Google Application Default Credentials if
you don’t pass any credentials of your own. If you are familiar with the
oauth2client library, you can create a credentials
object and
pass it directly:
client = Client(credentials=credentials)
In addition, the
from_service_account_json()
and
from_service_account_p12()
factories can be used if you know the specific type of credentials you’d
like to use.
Project ID¶
Tip
Be sure to use the Project ID, not the Project Number.
You can also explicitly provide the project_id
rather than relying
on the inferred value:
client = Client(project_id='my-cloud-console-project')
When implicit, the value is inferred from the environment in the following order:
- The
GCLOUD_PROJECT
environment variable - The Google App Engine application ID
- The Google Compute Engine project ID (from the metadata server)
Admin API Access¶
If you’ll be using your client to make Cluster Admin and Table Admin
API requests, you’ll need to pass the admin
argument:
client = Client(admin=True)
Read-Only Mode¶
If on the other hand, you only have (or want) read access to the data,
you can pass the read_only
argument:
client = Client(read_only=True)
This will ensure that the
READ_ONLY_SCOPE
is used
for API requests (so any accidental requests that would modify data will
fail).
Next Step¶
After a Client
, the next highest-level
object is a Cluster
. You’ll need
one before you can interact with tables or data.
Head next to learn about the Cluster Admin API.