Overview of APIs, client libraries, and ORM drivers

Available interfaces

You can use one of several programmatic interfaces when interacting with Spanner. These are the available interfaces, in the order that we recommend using them:

  • Client libraries: The Spanner client libraries are available in multiple languages and are built on gRPC. These client libraries provide a layer of abstraction on top of gRPC and handle the details of session management, transaction execution, retries, and more.
  • ORM and framework drivers: Google supports open-source Spanner drivers for several popular object-relational mapping libraries (ORMs) and frameworks, such as JDBC. These drivers allow the use of Spanner databases through APIs defined by those frameworks.
  • RPC API: If a client library or ORM driver is not available for your programming language of choice, use the RPC API, which is built on gRPC. gRPC offers a number of performance benefits compared with using the REST API, including representing objects in protocol buffer format (which are faster to produce and consume compared with JSON) and persistent connections (which result in less per-request overhead). Read more about these and other benefits in gRPC Concepts.
  • REST API: If you're unable to use Spanner's client libraries or the RPC API, use the REST API. Note that some features that are available in the RPC API are not supported in the REST API, as documented below.

RPC versus REST API

This table compares Spanner features available through its RPC and REST API interfaces.

Feature Supported in the RPC API? Supported in the REST API?
Cancelling a request Yes No
Setting a deadline or timeout on a request Yes No
Sending a streaming request Yes. see ExecuteStreamingSQL and StreamingRead. Partial. HTTP Streaming is supported but application-level flow control is not.

Client libraries features support

The following table lists the client libraries, noting the major Spanner features that each one supports.

Client Go Java Node.js Python Ruby C++ PHP C#
Batch DDL
Batch DML
Configurable leader option
Graph queries
Interleaved tables
JSON type
Mutations
Partitioned DML
Partitioned read
PostgreSQL interface
Request priority
Request tagging
Session labeling
Stale reads
Statement hints