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) -> Destination: 35 """Get a connector by name and version. 36 37 Args: 38 name: connector name 39 config: connector config - if not provided, you need to set it later via the set_config 40 method. 41 config_change_callback: callback function to be called when the connector config changes. 42 streams: list of stream names to select for reading. If set to "*", all streams will be 43 selected. If not provided, you can set it later via the `select_streams()` or 44 `select_all_streams()` method. 45 version: connector version - if not provided, the currently installed version will be used. 46 If no version is installed, the latest available version will be used. The version can 47 also be set to "latest" to force the use of the latest available version. 48 use_python: (Optional.) Python interpreter specification: 49 - True: Use current Python interpreter. (Inferred if `pip_url` is set.) 50 - False: Use Docker instead. 51 - Path: Use interpreter at this path. 52 - str: Use specific Python version. E.g. "3.11" or "3.11.10". If the version is not yet 53 installed, it will be installed by uv. (This generally adds less than 3 seconds 54 to install times.) 55 pip_url: connector pip URL - if not provided, the pip url will be inferred from the 56 connector name. 57 local_executable: If set, the connector will be assumed to already be installed and will be 58 executed using this path or executable name. Otherwise, the connector will be installed 59 automatically in a virtual environment. 60 docker_image: If set, the connector will be executed using Docker. You can specify `True` 61 to use the default image for the connector, or you can specify a custom image name. 62 If `version` is specified and your image name does not already contain a tag 63 (e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`). 64 use_host_network: If set, along with docker_image, the connector will be executed using 65 the host network. This is useful for connectors that need to access resources on 66 the host machine, such as a local database. This parameter is ignored when 67 `docker_image` is not set. 68 install_if_missing: Whether to install the connector if it is not available locally. This 69 parameter is ignored when local_executable is set. 70 install_root: (Optional.) The root directory where the virtual environment will be 71 created. If not provided, the current working directory will be used. 72 """ 73 return Destination( 74 name=name, 75 config=config, 76 config_change_callback=config_change_callback, 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 ), 88 ) 89 90 91def get_noop_destination( 92 *, 93 install_if_missing: bool = True, 94) -> Destination: 95 """Get a devnull (no-op) destination. 96 97 This is useful for performance benchmarking of sources, without 98 adding the overhead of writing data to a real destination. 99 """ 100 return get_destination( 101 "destination-dev-null", 102 config={ 103 "test_destination": { 104 "test_destination_type": "SILENT", 105 } 106 }, 107 docker_image=True, 108 install_if_missing=install_if_missing, 109 ) 110 111 112__all__ = [ 113 "get_destination", 114 "get_noop_destination", 115]
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) -> 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) -> 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 """ 74 return Destination( 75 name=name, 76 config=config, 77 config_change_callback=config_change_callback, 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 ), 89 )
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()
orselect_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.)
- True: Use current Python interpreter. (Inferred if
- 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. Ifversion
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.
92def get_noop_destination( 93 *, 94 install_if_missing: bool = True, 95) -> Destination: 96 """Get a devnull (no-op) destination. 97 98 This is useful for performance benchmarking of sources, without 99 adding the overhead of writing data to a real destination. 100 """ 101 return get_destination( 102 "destination-dev-null", 103 config={ 104 "test_destination": { 105 "test_destination_type": "SILENT", 106 } 107 }, 108 docker_image=True, 109 install_if_missing=install_if_missing, 110 )
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.