# Helpers

2.25.0 (latest) 2.24.0 2.23.0 2.22.0 2.21.0 2.20.2 2.19.0 2.18.0 2.17.0 2.16.1 2.15.2 2.14.0 2.13.2 2.12.0 2.11.1 2.10.0 2.9.0 2.8.3 2.7.2 2.6.2 2.5.1 2.4.0 2.3.0 2.2.0 2.1.6 2.0.1 1.15.5 1.14.0 1.13.2 1.12.0 1.11.0 1.10.0 1.9.0 Helper functions for dealing with Cloud Datastore's Protobuf API.

The non-private functions are part of the API.

### *class* google.cloud.datastore.helpers.GeoPoint(latitude, longitude)

Bases: [`object`](https://docs.python.org/3/library/functions.html#object)

Simple container for a geo point value.

- **Parameters**

  - **latitude** ([*float*](https://docs.python.org/3/library/functions.html#float)) -- Latitude of a point.

  - **longitude** ([*float*](https://docs.python.org/3/library/functions.html#float)) -- Longitude of a point.

#### _*eq_*(other)

Compare two geo points for equality.

- **Return type**

  [bool](https://docs.python.org/3/library/functions.html#bool)
- **Returns**

  True if the points compare equal, else False.

#### _*ne_*(other)

Compare two geo points for inequality.

- **Return type**

  [bool](https://docs.python.org/3/library/functions.html#bool)
- **Returns**

  False if the points compare equal, else True.

#### to_protobuf()

Convert the current object to protobuf.

- **Return type**

  `google.type.latlng_pb2.LatLng`.
- **Returns**

  The current point as a protobuf.

### google.cloud.datastore.helpers.entity_from_protobuf(pb)

Factory method for creating an entity based on a protobuf.

The protobuf should be one returned from the Cloud Datastore
Protobuf API.

- **Parameters**

  **pb** (`entity_pb2.Entity`) -- The Protobuf representing the entity.
- **Return type**

  [`google.cloud.datastore.entity.Entity`](https://docs.cloud.google.com/python/docs/reference/datastore/latest/entities#google.cloud.datastore.entity.Entity)
- **Returns**

  The entity derived from the protobuf.

### google.cloud.datastore.helpers.entity_to_protobuf(entity)

Converts an entity into a protobuf.

- **Parameters**

  **entity** ([`google.cloud.datastore.entity.Entity`](https://docs.cloud.google.com/python/docs/reference/datastore/latest/entities#google.cloud.datastore.entity.Entity)) -- The entity to be turned into a protobuf.
- **Return type**

  `entity_pb2.Entity`
- **Returns**

  The protobuf representing the entity.

### google.cloud.datastore.helpers.get_read_options(eventual, transaction_id, read_time=None, new_transaction_options=None)

Validate rules for read options, and assign to the request.

Helper method for `lookup()` and `run_query`.

- **Parameters**

  - **eventual** ([*bool*](https://docs.python.org/3/library/functions.html#bool)) -- Flag indicating if `EVENTUAL` or `STRONG`
    consistency should be used.

  - **transaction_id** ([*bytes*](https://docs.python.org/3/library/stdtypes.html#bytes)) -- A transaction identifier (may be null).

  - **read_time** (*datetime*) -- Read data from the specified time (may be null). This feature is in private preview.

  - **new_transaction_options** (`google.cloud.datastore_v1.types.TransactionOptions`) -- Options for a new transaction.

- **Return type**

  `datastore_pb2.ReadOptions`
- **Returns**

  The read options corresponding to the inputs.
- **Raises**

  [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError) if more than one of `eventual==True`,
  `transaction_id`, `read_time`, and `new_transaction_options` is specified.

### google.cloud.datastore.helpers.get_transaction_options(transaction)

Get the transaction_id or new_transaction_options field from an active transaction object,
for use in get_read_options

These are mutually-exclusive fields, so one or both will be None.

- **Return type**

  Tuple\[Optional\[[bytes](https://docs.python.org/3/library/stdtypes.html#bytes)\], Optional\[google.cloud.datastore_v1.types.TransactionOptions\]\]
- **Returns**

  The transaction_id and new_transaction_options fields from the transaction object.

### google.cloud.datastore.helpers.key_from_protobuf(pb)

Factory method for creating a key based on a protobuf.

The protobuf should be one returned from the Cloud Datastore
Protobuf API.

- **Parameters**

  **pb** (`entity_pb2.Key`) -- The Protobuf representing the key.
- **Return type**

  [`google.cloud.datastore.key.Key`](https://docs.cloud.google.com/python/docs/reference/datastore/latest/keys#google.cloud.datastore.key.Key)
- **Returns**

  a new Key instance

### google.cloud.datastore.helpers.set_database_id_to_request(request, database_id=None)

Set the "database_id" field to the request only if it was provided.