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 pip_url: str | None = None, 28 local_executable: Path | str | None = None, 29 docker_image: str | bool | None = None, 30 use_host_network: bool = False, 31 install_if_missing: bool = True, 32) -> Destination: 33 """Get a connector by name and version. 34 35 Args: 36 name: connector name 37 config: connector config - if not provided, you need to set it later via the set_config 38 method. 39 config_change_callback: callback function to be called when the connector config changes. 40 streams: list of stream names to select for reading. If set to "*", all streams will be 41 selected. If not provided, you can set it later via the `select_streams()` or 42 `select_all_streams()` method. 43 version: connector version - if not provided, the currently installed version will be used. 44 If no version is installed, the latest available version will be used. The version can 45 also be set to "latest" to force the use of the latest available version. 46 pip_url: connector pip URL - if not provided, the pip url will be inferred from the 47 connector name. 48 local_executable: If set, the connector will be assumed to already be installed and will be 49 executed using this path or executable name. Otherwise, the connector will be installed 50 automatically in a virtual environment. 51 docker_image: If set, the connector will be executed using Docker. You can specify `True` 52 to use the default image for the connector, or you can specify a custom image name. 53 If `version` is specified and your image name does not already contain a tag 54 (e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`). 55 use_host_network: If set, along with docker_image, the connector will be executed using 56 the host network. This is useful for connectors that need to access resources on 57 the host machine, such as a local database. This parameter is ignored when 58 `docker_image` is not set. 59 install_if_missing: Whether to install the connector if it is not available locally. This 60 parameter is ignored when local_executable is set. 61 """ 62 return Destination( 63 name=name, 64 config=config, 65 config_change_callback=config_change_callback, 66 executor=get_connector_executor( 67 name=name, 68 version=version, 69 pip_url=pip_url, 70 local_executable=local_executable, 71 docker_image=docker_image, 72 use_host_network=use_host_network, 73 install_if_missing=install_if_missing, 74 ), 75 ) 76 77 78def get_noop_destination( 79 *, 80 install_if_missing: bool = True, 81) -> Destination: 82 """Get a devnull (no-op) destination. 83 84 This is useful for performance benchmarking of sources, without 85 adding the overhead of writing data to a real destination. 86 """ 87 return get_destination( 88 "destination-dev-null", 89 config={ 90 "test_destination": { 91 "test_destination_type": "LOGGING", 92 "logging_config": { 93 "logging_type": "FirstN", 94 "max_entry_count": 100, 95 }, 96 } 97 }, 98 docker_image=True, 99 install_if_missing=install_if_missing, 100 ) 101 102 103__all__ = [ 104 "get_destination", 105 "get_noop_destination", 106]
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, 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) -> 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 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) -> Destination: 34 """Get a connector by name and version. 35 36 Args: 37 name: connector name 38 config: connector config - if not provided, you need to set it later via the set_config 39 method. 40 config_change_callback: callback function to be called when the connector config changes. 41 streams: list of stream names to select for reading. If set to "*", all streams will be 42 selected. If not provided, you can set it later via the `select_streams()` or 43 `select_all_streams()` method. 44 version: connector version - if not provided, the currently installed version will be used. 45 If no version is installed, the latest available version will be used. The version can 46 also be set to "latest" to force the use of the latest available version. 47 pip_url: connector pip URL - if not provided, the pip url will be inferred from the 48 connector name. 49 local_executable: If set, the connector will be assumed to already be installed and will be 50 executed using this path or executable name. Otherwise, the connector will be installed 51 automatically in a virtual environment. 52 docker_image: If set, the connector will be executed using Docker. You can specify `True` 53 to use the default image for the connector, or you can specify a custom image name. 54 If `version` is specified and your image name does not already contain a tag 55 (e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`). 56 use_host_network: If set, along with docker_image, the connector will be executed using 57 the host network. This is useful for connectors that need to access resources on 58 the host machine, such as a local database. This parameter is ignored when 59 `docker_image` is not set. 60 install_if_missing: Whether to install the connector if it is not available locally. This 61 parameter is ignored when local_executable is set. 62 """ 63 return Destination( 64 name=name, 65 config=config, 66 config_change_callback=config_change_callback, 67 executor=get_connector_executor( 68 name=name, 69 version=version, 70 pip_url=pip_url, 71 local_executable=local_executable, 72 docker_image=docker_image, 73 use_host_network=use_host_network, 74 install_if_missing=install_if_missing, 75 ), 76 )
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.
- 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.
79def get_noop_destination( 80 *, 81 install_if_missing: bool = True, 82) -> Destination: 83 """Get a devnull (no-op) destination. 84 85 This is useful for performance benchmarking of sources, without 86 adding the overhead of writing data to a real destination. 87 """ 88 return get_destination( 89 "destination-dev-null", 90 config={ 91 "test_destination": { 92 "test_destination_type": "LOGGING", 93 "logging_config": { 94 "logging_type": "FirstN", 95 "max_entry_count": 100, 96 }, 97 } 98 }, 99 docker_image=True, 100 install_if_missing=install_if_missing, 101 )
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.