airbyte.destinations.util

Destination utilities.

For usage examples, see the airbyte.destinations module documentation.

  1# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
  2"""Destination utilities.
  3
  4For usage examples, see the `airbyte.destinations` module documentation.
  5"""
  6
  7from __future__ import annotations
  8
  9from typing import TYPE_CHECKING, Any
 10
 11from airbyte._executors.util import get_connector_executor
 12from airbyte.destinations.base import Destination
 13
 14
 15if TYPE_CHECKING:
 16    from pathlib import Path
 17
 18    from airbyte.callbacks import ConfigChangeCallback
 19
 20
 21def get_destination(  # noqa: PLR0913 # Too many arguments
 22    name: str,
 23    config: dict[str, Any] | None = None,
 24    *,
 25    config_change_callback: ConfigChangeCallback | None = None,
 26    version: str | None = None,
 27    use_python: bool | Path | str | None = None,
 28    pip_url: str | None = None,
 29    local_executable: Path | str | None = None,
 30    docker_image: str | bool | None = None,
 31    use_host_network: bool = False,
 32    install_if_missing: bool = True,
 33    install_root: Path | None = None,
 34    no_executor: bool = False,
 35) -> Destination:
 36    """Get a connector by name and version.
 37
 38    Args:
 39        name: connector name
 40        config: connector config - if not provided, you need to set it later via the set_config
 41            method.
 42        config_change_callback: callback function to be called when the connector config changes.
 43        streams: list of stream names to select for reading. If set to "*", all streams will be
 44            selected. If not provided, you can set it later via the `select_streams()` or
 45            `select_all_streams()` method.
 46        version: connector version - if not provided, the currently installed version will be used.
 47            If no version is installed, the latest available version will be used. The version can
 48            also be set to "latest" to force the use of the latest available version.
 49        use_python: (Optional.) Python interpreter specification:
 50            - True: Use current Python interpreter. (Inferred if `pip_url` is set.)
 51            - False: Use Docker instead.
 52            - Path: Use interpreter at this path.
 53            - str: Use specific Python version. E.g. "3.11" or "3.11.10". If the version is not yet
 54                installed, it will be installed by uv. (This generally adds less than 3 seconds
 55                to install times.)
 56        pip_url: connector pip URL - if not provided, the pip url will be inferred from the
 57            connector name.
 58        local_executable: If set, the connector will be assumed to already be installed and will be
 59            executed using this path or executable name. Otherwise, the connector will be installed
 60            automatically in a virtual environment.
 61        docker_image: If set, the connector will be executed using Docker. You can specify `True`
 62            to use the default image for the connector, or you can specify a custom image name.
 63            If `version` is specified and your image name does not already contain a tag
 64            (e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`).
 65        use_host_network: If set, along with docker_image, the connector will be executed using
 66            the host network. This is useful for connectors that need to access resources on
 67            the host machine, such as a local database. This parameter is ignored when
 68            `docker_image` is not set.
 69        install_if_missing: Whether to install the connector if it is not available locally. This
 70            parameter is ignored when local_executable is set.
 71        install_root: (Optional.) The root directory where the virtual environment will be
 72            created. If not provided, the current working directory will be used.
 73        no_executor: If True, use NoOpExecutor which fetches specs from the registry without
 74            local installation. This is useful for scenarios where you need to validate
 75            configurations but don't need to run the connector locally (e.g., deploying to Cloud).
 76    """
 77    executor = get_connector_executor(
 78        name=name,
 79        version=version,
 80        use_python=use_python,
 81        pip_url=pip_url,
 82        local_executable=local_executable,
 83        docker_image=docker_image,
 84        use_host_network=use_host_network,
 85        install_if_missing=install_if_missing,
 86        install_root=install_root,
 87        no_executor=no_executor,
 88    )
 89
 90    return Destination(
 91        name=name,
 92        config=config,
 93        config_change_callback=config_change_callback,
 94        executor=executor,
 95    )
 96
 97
 98def get_noop_destination(
 99    *,
100    install_if_missing: bool = True,
101) -> Destination:
102    """Get a devnull (no-op) destination.
103
104    This is useful for performance benchmarking of sources, without
105    adding the overhead of writing data to a real destination.
106    """
107    return get_destination(
108        "destination-dev-null",
109        config={
110            "test_destination": {
111                "test_destination_type": "SILENT",
112            }
113        },
114        docker_image=True,
115        install_if_missing=install_if_missing,
116    )
117
118
119__all__ = [
120    "get_destination",
121    "get_noop_destination",
122]
def get_destination( name: str, config: dict[str, typing.Any] | None = None, *, config_change_callback: Callable[[dict[str, typing.Any]], None] | None = None, version: str | None = None, use_python: bool | pathlib.Path | str | None = None, pip_url: str | None = None, local_executable: pathlib.Path | str | None = None, docker_image: str | bool | None = None, use_host_network: bool = False, install_if_missing: bool = True, install_root: pathlib.Path | None = None, no_executor: bool = False) -> airbyte.Destination:
22def get_destination(  # noqa: PLR0913 # Too many arguments
23    name: str,
24    config: dict[str, Any] | None = None,
25    *,
26    config_change_callback: ConfigChangeCallback | None = None,
27    version: str | None = None,
28    use_python: bool | Path | str | None = None,
29    pip_url: str | None = None,
30    local_executable: Path | str | None = None,
31    docker_image: str | bool | None = None,
32    use_host_network: bool = False,
33    install_if_missing: bool = True,
34    install_root: Path | None = None,
35    no_executor: bool = False,
36) -> Destination:
37    """Get a connector by name and version.
38
39    Args:
40        name: connector name
41        config: connector config - if not provided, you need to set it later via the set_config
42            method.
43        config_change_callback: callback function to be called when the connector config changes.
44        streams: list of stream names to select for reading. If set to "*", all streams will be
45            selected. If not provided, you can set it later via the `select_streams()` or
46            `select_all_streams()` method.
47        version: connector version - if not provided, the currently installed version will be used.
48            If no version is installed, the latest available version will be used. The version can
49            also be set to "latest" to force the use of the latest available version.
50        use_python: (Optional.) Python interpreter specification:
51            - True: Use current Python interpreter. (Inferred if `pip_url` is set.)
52            - False: Use Docker instead.
53            - Path: Use interpreter at this path.
54            - str: Use specific Python version. E.g. "3.11" or "3.11.10". If the version is not yet
55                installed, it will be installed by uv. (This generally adds less than 3 seconds
56                to install times.)
57        pip_url: connector pip URL - if not provided, the pip url will be inferred from the
58            connector name.
59        local_executable: If set, the connector will be assumed to already be installed and will be
60            executed using this path or executable name. Otherwise, the connector will be installed
61            automatically in a virtual environment.
62        docker_image: If set, the connector will be executed using Docker. You can specify `True`
63            to use the default image for the connector, or you can specify a custom image name.
64            If `version` is specified and your image name does not already contain a tag
65            (e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`).
66        use_host_network: If set, along with docker_image, the connector will be executed using
67            the host network. This is useful for connectors that need to access resources on
68            the host machine, such as a local database. This parameter is ignored when
69            `docker_image` is not set.
70        install_if_missing: Whether to install the connector if it is not available locally. This
71            parameter is ignored when local_executable is set.
72        install_root: (Optional.) The root directory where the virtual environment will be
73            created. If not provided, the current working directory will be used.
74        no_executor: If True, use NoOpExecutor which fetches specs from the registry without
75            local installation. This is useful for scenarios where you need to validate
76            configurations but don't need to run the connector locally (e.g., deploying to Cloud).
77    """
78    executor = get_connector_executor(
79        name=name,
80        version=version,
81        use_python=use_python,
82        pip_url=pip_url,
83        local_executable=local_executable,
84        docker_image=docker_image,
85        use_host_network=use_host_network,
86        install_if_missing=install_if_missing,
87        install_root=install_root,
88        no_executor=no_executor,
89    )
90
91    return Destination(
92        name=name,
93        config=config,
94        config_change_callback=config_change_callback,
95        executor=executor,
96    )

Get a connector by name and version.

Arguments:
  • name: connector name
  • config: connector config - if not provided, you need to set it later via the set_config method.
  • config_change_callback: callback function to be called when the connector config changes.
  • streams: list of stream names to select for reading. If set to "*", all streams will be selected. If not provided, you can set it later via the select_streams() or select_all_streams() method.
  • version: connector version - if not provided, the currently installed version will be used. If no version is installed, the latest available version will be used. The version can also be set to "latest" to force the use of the latest available version.
  • use_python: (Optional.) Python interpreter specification:
    • True: Use current Python interpreter. (Inferred if pip_url is set.)
    • False: Use Docker instead.
    • Path: Use interpreter at this path.
    • str: Use specific Python version. E.g. "3.11" or "3.11.10". If the version is not yet installed, it will be installed by uv. (This generally adds less than 3 seconds to install times.)
  • pip_url: connector pip URL - if not provided, the pip url will be inferred from the connector name.
  • local_executable: If set, the connector will be assumed to already be installed and will be executed using this path or executable name. Otherwise, the connector will be installed automatically in a virtual environment.
  • docker_image: If set, the connector will be executed using Docker. You can specify True to use the default image for the connector, or you can specify a custom image name. If version is specified and your image name does not already contain a tag (e.g. my-image:latest), the version will be appended as a tag (e.g. my-image:0.1.0).
  • use_host_network: If set, along with docker_image, the connector will be executed using the host network. This is useful for connectors that need to access resources on the host machine, such as a local database. This parameter is ignored when docker_image is not set.
  • install_if_missing: Whether to install the connector if it is not available locally. This parameter is ignored when local_executable is set.
  • install_root: (Optional.) The root directory where the virtual environment will be created. If not provided, the current working directory will be used.
  • no_executor: If True, use NoOpExecutor which fetches specs from the registry without local installation. This is useful for scenarios where you need to validate configurations but don't need to run the connector locally (e.g., deploying to Cloud).
def get_noop_destination( *, install_if_missing: bool = True) -> airbyte.Destination:
 99def get_noop_destination(
100    *,
101    install_if_missing: bool = True,
102) -> Destination:
103    """Get a devnull (no-op) destination.
104
105    This is useful for performance benchmarking of sources, without
106    adding the overhead of writing data to a real destination.
107    """
108    return get_destination(
109        "destination-dev-null",
110        config={
111            "test_destination": {
112                "test_destination_type": "SILENT",
113            }
114        },
115        docker_image=True,
116        install_if_missing=install_if_missing,
117    )

Get a devnull (no-op) destination.

This is useful for performance benchmarking of sources, without adding the overhead of writing data to a real destination.