---
title: Build a custom connector for Lakeflow Connect
description: Build, test, and deploy a custom connector in your own Databricks workspace to ingest data from a source that has no managed connector in Lakeflow Connect.
canonical_url: https://docs.databricks.com/aws/en/ingestion/custom-connectors
---

# Build a custom connector for Lakeflow Connect

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md).

Custom connectors let you ingest data from a source that Lakeflow Connect doesn't support with a managed connector. You build and test your connector, then deploy and run it in your own Databricks workspace. You don't need to register it with the community or contribute it to any shared repository to use it.

Develop your connector using the tools and templates in the [Lakeflow Community Connectors](https://github.com/databrickslabs/lakeflow-community-connectors) repository on GitHub. The repository includes AI-powered development tools to assist with each phase, including source research, authentication setup, implementation, and testing.

If you later want to share your connector with other users, you can [contribute it to the community](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#contribute). To use an existing community connector, see [Community connectors in Lakeflow Connect](https://docs.databricks.com/aws/en/ingestion/community-connectors.md).

## <a id="requirements" />Requirements

Before you start, make sure you have:

* Python 3.10 or above
* A Databricks workspace with Unity Catalog enabled
* API credentials for the source you want to connect to
* Git installed locally
* The [Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md) installed and authenticated to your workspace with a [configuration profile](https://docs.databricks.com/aws/en/dev-tools/auth/config-profiles.md)

## <a id="setup" />Set up the repository

Clone the [Lakeflow Community Connectors](https://github.com/databrickslabs/lakeflow-community-connectors) repository, install the development dependencies, and install the Community Connector CLI.

1. Clone the repository:

   ```bash
   git clone https://github.com/databrickslabs/lakeflow-community-connectors.git
   cd lakeflow-community-connectors
   ```

2. Create a virtual environment and install dependencies:

   ```bash
   python -m venv .venv
   source .venv/bin/activate
   pip install -e ".[dev]"
   ```

3. In the same virtual environment, install the Community Connector CLI. The repository's `/deploy-connector` command and the [CLI deployment path](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#deploy-cli) both require the `community-connector` command that this step installs. To install the CLI, run the following:

   ```bash
   cd tools/community_connector
   pip install -e .
   cd ../..
   ```

   The CLI uses the same authentication as the Databricks CLI. If your `~/.databrickscfg` file has more than one profile, set the `DATABRICKS_CONFIG_PROFILE` environment variable to the profile to use. Otherwise, the CLI uses the `DEFAULT` profile.

4. Review the existing connector implementations in `src/databricks/labs/community_connector/sources/`, then start developing your connector in a new directory under that path. Follow the repository's AI-assisted development commands and skills. For the recommended workflow, use:

   ```text
   /develop-connector <your-source>
   /validate-connector <your-source>
   ```

## <a id="implement" />Implement the `LakeflowConnect` interface

Each connector implements the `LakeflowConnect` interface, which defines how your connector authenticates, discovers tables, returns schemas, and reads data.

```python
class LakeflowConnect:
    def __init__(self, options: dict[str, str]) -> None:
        """Initialize with connection parameters"""

    def list_tables(self) -> list[str]:
        """Return names of all tables supported by this connector."""

    def get_table_schema(self, table_name: str, table_options: dict[str, str]) -> StructType:
        """Return the Spark schema for a table."""

    def read_table_metadata(self, table_name: str, table_options: dict[str, str]) -> dict:
        """Return metadata: primary_keys, cursor_field, ingestion_type
        (snapshot|cdc|cdc_with_deletes|append)."""

    def read_table(self, table_name: str, start_offset: dict,
                   table_options: dict[str, str]) -> (Iterator[dict], dict):
        """Yield records as JSON dicts and return the next offset
        for incremental reads."""

    def read_table_deletes(self, table_name: str, start_offset: dict,
                           table_options: dict[str, str]) -> (Iterator[dict], dict):
        """Optional: Only required if ingestion_type is 'cdc_with_deletes'."""
```

### <a id="methods" />Method descriptions

The following table describes each method in the `LakeflowConnect` interface:

| Method                | Description                                                                                                                                                                                                  |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `__init__`            | Receives the connection parameters as a dictionary and initializes the API client for your source.                                                                                                           |
| `list_tables`         | Returns the names of all tables (or API endpoints) your connector exposes. Databricks uses this list to populate the table selection UI.                                                                     |
| `get_table_schema`    | Returns a Spark `StructType` describing the schema for the given table. Called before the first pipeline run and on each run when schema evolution is enabled.                                               |
| `read_table_metadata` | Returns a dictionary with `primary_keys`, `cursor_field`, and `ingestion_type`. The `ingestion_type` must be one of `snapshot`, `cdc`, `cdc_with_deletes`, or `append`.                                      |
| `read_table`          | Yields records as Python dictionaries and returns the next offset for incremental reads. On the first run, `start_offset` is empty. On subsequent runs, it contains the offset returned by the previous run. |
| `read_table_deletes`  | Optional. Only implement this method if `ingestion_type` is `cdc_with_deletes`. Yields deleted record keys and returns the next offset.                                                                      |

## <a id="dev-workflow" />Develop your connector

Follow these steps to build and validate a new connector:

1. **Research the source API**: Study the source's API specifications, authentication mechanisms, rate limits, and available data schemas. Identify which tables or endpoints to expose.

2. **Set up authentication**: Generate the connection specification, configure credentials for the source, and verify connectivity from your development environment.

3. **Implement the connector**: Code all required `LakeflowConnect` interface methods to connect to the source API and return data in the expected format.

4. **Test and iterate**: Run the standard test suites against a real source system and fix any issues. See [Test your connector](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#test) for details.

5. **Document the connector**: Write a user-facing `README.md` and generate the connector spec YAML file that describes the connector's configurable parameters.

6. **Build the deployment artifact**: Run the build script to produce the single-file artifact that can be deployed in a workspace.

## <a id="test" />Test your connector

The repository provides several testing approaches:

### Generic test suite (required)

This suite connects to a real source using your provided credentials to verify end-to-end functionality, including authentication, schema discovery, and data reads.

```bash
python -m pytest tests/generic/ --connector <your-source> --credentials credentials.json
```

### Write-back testing (recommended)

Write-back testing runs write-read-verify cycles to validate incremental reads and deletes. This confirms that your offset tracking and CDC logic work correctly.

```bash
python -m pytest tests/writeback/ --connector <your-source> --credentials credentials.json
```

### Unit tests

Write unit tests for any complex custom logic in your connector, such as pagination handling, type coercion, or error recovery.

## <a id="build" />Build the deployment artifact

After your connector passes the test suites, package it so a pipeline can run it. A connector deploys as two parts:

* **A single-file source artifact.** Run the merge script to flatten your connector into one self-contained Python file. The pipeline uses this file at runtime rather than the full repository.

  ```bash
  python tools/scripts/merge_python_source.py --connector <your-source>
  ```

  The script writes this file to `dist/<your-source>/`.

* **Python wheels (`.whl`) for the connector's dependencies.** The connector framework and any third-party libraries your connector imports must be available to the pipeline as wheels stored in a Unity Catalog volume. If these wheels are missing, the pipeline can fail during source discovery. You can upload them yourself and reference them in the UI, or let the Community Connector CLI build and upload them for you. See [Deploy with the Community Connector CLI](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#deploy-cli).

Deploy your connector in one of two ways:

* **The Databricks UI** is the point-and-click path. Use it for a one-off deployment when you provide the connector's wheels yourself in the **Library dependencies** field. See [Deploy in the Databricks UI](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#create-pipeline).
* **The `community-connector` CLI** is the scriptable path. Use it when you're developing locally and want the connector's wheels built and uploaded for you, or when you want a repeatable deployment you can automate. See [Deploy with the Community Connector CLI](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#deploy-cli).

## <a id="create-pipeline" />Deploy in the Databricks UI

Deploy your connector in the Databricks UI in two phases: add the connector, then create the pipeline.

### <a id="add-connector" />Add the custom connector

First, add your connector so that it appears as a tile on the **Add data** page:

1. In the sidebar of your Databricks workspace, click **+New** > **Add or upload data**, then, under **Community and custom connectors**, click **Add Custom Connector**.
2. For **Source name**, enter the name of your connector. This must match the directory name that contains your connector's source code (`sources/<source-name>`). Use only letters, numbers, underscores, and hyphens.
3. For **Display name**, enter a friendly name for the connector. If you leave this blank, it defaults to the source name.
4. For **Library dependencies**, add the Python wheel (`.whl`) files your connector needs from a Unity Catalog volume. See [Build the deployment artifact](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#build).
5. For **Connection specification**, paste the connector's connection specification in YAML, matching its `connector_spec.yaml` file.
6. Click **Save**.

Databricks saves the connector to your workspace. The connector appears as a tile tagged **Custom** under **Community and custom connectors**. It can take a few minutes for a new tile to appear.

### <a id="run-pipeline" />Create the ingestion pipeline

Then create the pipeline that ingests data from your source:

1. Select your connector tile to open the ingestion wizard.
2. On the **Connection** step, click **Create connection** or select an existing connection, enter the connection details for your source, then click **Next**.
3. On the **Ingestion setup** step, enter a **Pipeline name**, select a catalog and schema for the **Event log location**, choose a **Compute type**, then click **Create pipeline and continue**. The pipeline uses the wheels that you added in **Library dependencies**, so this step doesn't ask for them.
4. On the **Source** step, select the tables to ingest. You can also choose the slowly changing dimension (SCD) type for each table.
5. On the **Destination** step, choose the catalog and schema where ingested tables are written.
6. On the **Schedules and notifications** step, optionally set a schedule and notifications, then click **Save and run pipeline**. If you didn't change any settings on this step, the button is **Run pipeline**.

## <a id="deploy-cli" />Deploy with the Community Connector CLI

Before you use the CLI, install it as described in [Set up the repository](https://docs.databricks.com/aws/en/ingestion/custom-connectors.md#setup).

The CLI's `publish` command builds the framework and connector wheels from your local source, uploads them to a Unity Catalog volume, records their paths in the connector manifest, and publishes the connector as a **Custom** tile on the **Add data** page. Point it at your local connector spec so it doesn't look for the connector in the upstream repository:

```bash
community-connector publish <your-source> \
  --spec src/databricks/labs/community_connector/sources/<your-source>/connector_spec.yaml
```

To reuse wheels you already built and skip the build step, pass them with `--package`. To replace a connector you published earlier, add `--overwrite`. For the full list of options, including `--package`, `--volume-path`, `--catalog`, and `--schema`, see the [`publish` command reference](https://github.com/databrickslabs/lakeflow-community-connectors/tree/master/tools/community_connector#publish).

To run the entire workflow from the command line, including creating a connection, creating and updating the ingestion pipeline, publishing, and unpublishing, see the [Community Connector CLI reference](https://github.com/databrickslabs/lakeflow-community-connectors/tree/master/tools/community_connector).

## <a id="contribute" />Contribute your connector to the community

Your connector runs in your workspace whether or not you contribute it. If you want to share it so other users can discover and use it, open a pull request in the [Lakeflow Community Connectors](https://github.com/databrickslabs/lakeflow-community-connectors) repository. Contributed connectors become [community connectors](https://docs.databricks.com/aws/en/ingestion/community-connectors.md), which the community maintains and which aren't backed by Databricks SLAs.
