Build a custom connector for Lakeflow Connect
This feature is in Beta. Workspace admins can control access to this feature from the Previews page. See Manage Databricks previews.
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 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. To use an existing community connector, see Community connectors in Lakeflow Connect.
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
Set up the repository
Clone the Lakeflow Community Connectors repository and install the development dependencies.
-
Clone the repository:
Bashgit clone https://github.com/databrickslabs/lakeflow-community-connectors.git
cd lakeflow-community-connectors -
Create a virtual environment and install dependencies:
Bashpython -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]" -
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>
Implement the LakeflowConnect interface
Each connector implements the LakeflowConnect interface, which defines how your connector authenticates, discovers tables, returns schemas, and reads data.
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'."""
Method descriptions
The following table describes each method in the LakeflowConnect interface:
Method | Description |
|---|---|
| Receives the connection parameters as a dictionary and initializes the API client for your source. |
| Returns the names of all tables (or API endpoints) your connector exposes. Databricks uses this list to populate the table selection UI. |
| Returns a Spark |
| Returns a dictionary with |
| Yields records as Python dictionaries and returns the next offset for incremental reads. On the first run, |
| Optional. Only implement this method if |
Develop your connector
Follow these steps to build and validate a new connector:
-
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.
-
Set up authentication: Generate the connection specification, configure credentials for the source, and verify connectivity from your development environment.
-
Implement the connector: Code all required
LakeflowConnectinterface methods to connect to the source API and return data in the expected format. -
Test and iterate: Run the standard test suites against a real source system and fix any issues. See Test your connector for details.
-
Document the connector: Write a user-facing
README.mdand generate the connector spec YAML file that describes the connector's configurable parameters. -
Build the deployment artifact: Run the build script to produce the single-file artifact that can be deployed in a workspace.
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.
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.
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.
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.
Bashpython 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.
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.
- The
community-connectorCLI 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.
Deploy in the Databricks UI
Deploy your connector in the Databricks UI in two phases: add the connector, then create the pipeline.
Add the custom connector
First, add your connector so that it appears as a tile on the Add data page:
- In the sidebar of your Databricks workspace, click +New > Add or upload data, then, under Community connectors, add a custom connector.
- 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>). - For Display name, enter a friendly name for the connector. If you leave this blank, it defaults to the source name.
- For Library dependencies, add the Python wheel (
.whl) files your connector needs from a Unity Catalog volume. See Build the deployment artifact. - For Connection specification, paste the connector's connection specification in YAML, matching its
connector_spec.yamlfile. - Click Save. The connector appears as a Custom tile under Community connectors.
Create the ingestion pipeline
Then create the pipeline that ingests data from your source:
- Select your connector tile to open the Ingest data wizard.
- On the Connection step, click + Create connection or select an existing connection, enter the connection details for your source, then click Next.
- On the Ingestion setup step, enter a Pipeline name, set the Event log location (catalog and schema), choose a Compute type, then click Create pipeline and continue.
- On the Source step, select the tables to ingest.
- On the Destination step, choose the catalog and schema where ingested tables are written.
- On the Schedules and notifications step, set an optional schedule and notifications, then finish.
- Run the pipeline manually or on its schedule.
To configure the pipeline further, you can edit ingest.py in the pipeline editor. See Pipeline configuration options.
Pipeline configuration options
You can configure the following options in ingest.py:
Option | Description |
|---|---|
| Required. The name of the connection that stores authentication credentials for the source. |
| Required. A list of tables to ingest. Each entry has the format |
| The catalog where ingested tables are written. Defaults to the catalog set during pipeline creation. |
| The schema where ingested tables are written. Defaults to the schema set during pipeline creation. |
| The slowly changing dimension strategy: |
| Override the default primary keys for a table. Provide a list of column names. |
Deploy with the Community Connector CLI
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:
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.
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.
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 repository. Contributed connectors become community connectors, which the community maintains and which aren't backed by Databricks SLAs.