Skip to content

Commit 326683c

Browse files
authored
Feat: Promote get_source() args for docker_image and source_manifest out of experimental status (#294)
1 parent f5f7b03 commit 326683c

File tree

8 files changed

+30
-69
lines changed

8 files changed

+30
-69
lines changed

airbyte/experimental/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
22
"""Experimental features which may change.
33
4+
> **NOTE:**
5+
> The below "experimental" features are now "stable" and can be accessed directly from the
6+
`airbyte.get_source()` method.
7+
48
The experimental `get_source` implementation allows you to run sources
59
using Docker containers. This feature is still in development and may
610
change in the future.
@@ -34,7 +38,7 @@
3438

3539
from __future__ import annotations
3640

37-
from airbyte.sources.util import _get_source as get_source
41+
from airbyte.sources.util import get_source
3842

3943

4044
__all__ = [

airbyte/sources/util.py

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def get_connector(
4848
)
4949

5050

51-
# This non-public function includes the `docker_image` parameter, which is not exposed in the
52-
# public API. See the `experimental` module for more info.
53-
def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
51+
def get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
5452
name: str,
5553
config: dict[str, Any] | None = None,
5654
*,
@@ -87,13 +85,14 @@ def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
8785
(e.g. `my-image:latest`), the version will be appended as a tag (e.g. `my-image:0.1.0`).
8886
use_host_network: If set, along with docker_image, the connector will be executed using
8987
the host network. This is useful for connectors that need to access resources on
90-
the host machine, such as a local database.
91-
source_manifest: If set, the connector will be executed based on a declarative Yaml
92-
source definition. This input can be `True` to auto-download the yaml spec, `dict`
93-
to accept a Python dictionary as the manifest, `Path` to pull a manifest from
88+
the host machine, such as a local database. This parameter is ignored when
89+
`docker_image` is not set.
90+
source_manifest: If set, the connector will be executed based on a declarative YAML
91+
source definition. This input can be `True` to attempt to auto-download a YAML spec,
92+
`dict` to accept a Python dictionary as the manifest, `Path` to pull a manifest from
9493
the local file system, or `str` to pull the definition from a web URL.
9594
install_if_missing: Whether to install the connector if it is not available locally. This
96-
parameter is ignored when local_executable is set.
95+
parameter is ignored when `local_executable` or `source_manifest` are set.
9796
install_root: (Optional.) The root directory where the virtual environment will be
9897
created. If not provided, the current working directory will be used.
9998
"""
@@ -206,13 +205,15 @@ def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
206205

207206
if source_manifest:
208207
if source_manifest is True:
209-
http_url = (
208+
# Auto-set the manifest to a valid http address URL string
209+
source_manifest = (
210210
"https://raw.githubusercontent.com/airbytehq/airbyte/master/airbyte-integrations"
211211
f"/connectors/{name}/{name.replace('-', '_')}/manifest.yaml"
212212
)
213-
print("Installing connector from YAML manifest:", http_url)
214-
# Download the file
215-
response = requests.get(http_url)
213+
if isinstance(source_manifest, str):
214+
print("Installing connector from YAML manifest:", source_manifest)
215+
# Download the manifest file
216+
response = requests.get(url=source_manifest)
216217
response.raise_for_status() # Raise an exception if the download failed
217218

218219
if "class_name:" in response.text:
@@ -225,7 +226,7 @@ def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
225226
),
226227
connector_name=name,
227228
context={
228-
"manifest_url": http_url,
229+
"manifest_url": source_manifest,
229230
},
230231
)
231232

@@ -235,10 +236,14 @@ def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
235236
raise exc.AirbyteConnectorInstallationError(
236237
connector_name=name,
237238
context={
238-
"manifest_url": http_url,
239+
"manifest_url": source_manifest,
239240
},
240241
) from ex
241242

243+
if isinstance(source_manifest, Path):
244+
source_manifest = cast(dict, yaml.safe_load(source_manifest.read_text()))
245+
246+
# Source manifest is a dict at this point
242247
return Source(
243248
name=name,
244249
config=config,
@@ -280,54 +285,6 @@ def _get_source( # noqa: PLR0912, PLR0913, PLR0915 # Too complex
280285
raise
281286

282287

283-
# This thin wrapper exposes only non-experimental functions.
284-
# Aka, exclude the `docker_image` parameter for now.
285-
# See the `experimental` module for more info.
286-
def get_source(
287-
name: str,
288-
config: dict[str, Any] | None = None,
289-
*,
290-
streams: str | list[str] | None = None,
291-
version: str | None = None,
292-
pip_url: str | None = None,
293-
local_executable: Path | str | None = None,
294-
install_if_missing: bool = True,
295-
install_root: Path | None = None,
296-
) -> Source:
297-
"""Get a connector by name and version.
298-
299-
Args:
300-
name: connector name
301-
config: connector config - if not provided, you need to set it later via the set_config
302-
method.
303-
streams: list of stream names to select for reading. If set to "*", all streams will be
304-
selected. If not provided, you can set it later via the `select_streams()` or
305-
`select_all_streams()` method.
306-
version: connector version - if not provided, the currently installed version will be used.
307-
If no version is installed, the latest available version will be used. The version can
308-
also be set to "latest" to force the use of the latest available version.
309-
pip_url: connector pip URL - if not provided, the pip url will be inferred from the
310-
connector name.
311-
local_executable: If set, the connector will be assumed to already be installed and will be
312-
executed using this path or executable name. Otherwise, the connector will be installed
313-
automatically in a virtual environment.
314-
install_if_missing: Whether to install the connector if it is not available locally. This
315-
parameter is ignored when local_executable is set.
316-
install_root: (Optional.) The root directory where the virtual environment will be
317-
created. If not provided, the current working directory will be used.
318-
"""
319-
return _get_source(
320-
name=name,
321-
config=config,
322-
streams=streams,
323-
version=version,
324-
pip_url=pip_url,
325-
local_executable=local_executable,
326-
install_if_missing=install_if_missing,
327-
install_root=install_root,
328-
)
329-
330-
331288
__all__ = [
332289
"get_source",
333290
]

examples/run_declarative_manifest_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import yaml
1414

15-
from airbyte.experimental import get_source
15+
from airbyte import get_source
1616

1717

1818
# Copy-pasted from the Builder "Yaml" view:

examples/run_downloadable_yaml_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from __future__ import annotations
1010

1111
import airbyte as ab
12-
from airbyte.experimental import get_source
12+
from airbyte import get_source
1313

1414

1515
yaml_connectors: list[str] = ab.get_available_connectors(install_type="yaml")

examples/run_pokeapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from __future__ import annotations
1212

1313
import airbyte as ab
14-
from airbyte.experimental import get_source
14+
from airbyte import get_source
1515

1616

1717
source = get_source(

tests/integration_tests/test_all_cache_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
import airbyte as ab
1616
import pytest
17+
from airbyte import get_source
1718
from airbyte._executor import _get_bin_dir
18-
from airbyte.experimental import get_source
1919
from airbyte.progress import ReadProgress, progress
2020

2121
# Product count is always the same, regardless of faker scale.

tests/integration_tests/test_lowcode_connectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import jsonschema
88
import pytest
99
from airbyte import exceptions as exc
10-
from airbyte.experimental import get_source
10+
from airbyte import get_source
1111
from airbyte.sources.registry import (
1212
_LOWCODE_CONNECTORS_404,
1313
_LOWCODE_CONNECTORS_FAILING_VALIDATION,

tests/unit_tests/test_lowcode_connectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from pathlib import Path
55

66
import pytest
7+
from airbyte import get_source
78
from airbyte._util.meta import is_windows
8-
from airbyte.experimental import get_source
99

1010
UNIT_TEST_DB_PATH: Path = Path(".cache") / "unit_tests" / "test_db.duckdb"
1111

0 commit comments

Comments
 (0)