> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdv/integration/db/integration/spanner.md).

# ❖ Spanner

This page describes how to integrate with your Spanner database. The Spanner integration supports both GoogleSQL and PostgreSQL.

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **AI Connectors Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [AI Connectors Bundle](/sdv/explore/sdv-bundles/ai-connectors.md) page.
{% endhint %}

## Installation

To use this feature, please make sure you have installed the bundle with the optional `db-spanner` dependency. For more information, see the [SDV Enterprise Installation guide](https://docs.sdv.dev/sdv-enterprise/installation/instructions).

```bash
pip install sdv-installer --upgrade
sdv-installer install --package bundle-ai-connectors --options db-spanner
```

## Connector

&#x20;Create a connector object that interacts with your Spanner database.

```python
from sdv.io.database import SpannerConnector

connector = SpannerConnector()
```

**Parameters** (None)

**Output** A SpannerConnector object that you can use to import data and metadata

## Config File

Create a YAML file that corresponds to the database to connect to. You will need separate config files for your source dataset (for importing training data) and a destination dataset (for exporting synthetic data).

The config file has the following structure:

```yaml
connection:
  database_name: <string> 
  schema_name: <string>

auth:
  json_credentials_path: <filepath>

options.SpannerConnector:
  instance_id: <id_value>
```

**Parameters**:

**`connection`**: This section defines the database tables you want to connect to. It is common to all Google-native databases.

* (required) `database_name`: A top-level logical container for data and database objects within a database system.
* (required) `schema_name`: A named logical grouping of database objects within a database, used for organization and access control.

**`auth`:** This section provides information about your identity, which is required to connect to the database. It is common to all Google-native databases.

* (required) `json_credentials_filepath`: A string with the file that contains the credentials. This can be downloaded for user or service accounts via Google's interface. *Follow the instructions in* [*these docs*](https://developers.google.com/workspace/guides/create-credentials#create_credentials_for_a_service_account) *to select your account, add a key, and download the JSON file. (If you need help with this step, please contact your database admin.)*

**`options.SpannerConnector`**: This section includes information that is specific for Spanner databases.

* (required) `instance_id`: The unique identifier of the Cloud Spanner instance that contains the databases. In Spanner, an instance is the top-level compute and configuration container.

## Setting Your Config File

Use the `set_import_config` and `set_export_config` functions to add your config YAML file to your connector.

```python
connector.set_import_config(filepath='source_db_config.yaml')
connector.set_export_config(filepath='destination_db_config.yaml')
```

Use the connector to create metadata, import a subset of training data, and export synthetic data. For more information, see the [Usage API](/sdv/integration/db/api.md).

## FAQ

<details>

<summary>Which permissions are needed for importing and exporting?</summary>

**Importing data requires read access.** For Spanner, this includes: `spanner.databases.list`,  `spanner.databases.read`, `spanner.databases.select`, `spanner.instances.get`, `spanner.instances.list`, `spanner.sessions.create`, `spanner.sessions.get`, `spanner.sessions.list`

**Exporting data requires write access.** For Spanner, this includes: `spanner.databaseOperations.get`, `spanner.databases.get`, `spanner.databases.getDdl`, `spanner.databases.list`, `spanner.databases.select`, `spanner.databases.updateDdl`, `spanner.databases.write`, `spanner.instances.list`, `spanner.sessions.create`, `spanner.sessions.get`

For official Spanner documentation about roles and permissions, [click here](https://cloud.google.com/spanner/docs/iam). If you do not have these permissions, please contact your database admin.

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sdv.dev/sdv/integration/db/integration/spanner.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
