airbyte.sources.registry
Backwards compatibility shim for airbyte.sources.registry.
This module re-exports symbols from airbyte.registry for backwards compatibility. New code should import from airbyte.registry directly.
1# Copyright (c) 2023 Airbyte, Inc., all rights reserved. 2"""Backwards compatibility shim for airbyte.sources.registry. 3 4This module re-exports symbols from airbyte.registry for backwards compatibility. 5New code should import from airbyte.registry directly. 6""" 7 8from __future__ import annotations 9 10from airbyte.registry import ( 11 ConnectorMetadata, 12 InstallType, 13 Language, 14 get_available_connectors, 15 get_connector_metadata, 16) 17 18 19__all__ = [ 20 "ConnectorMetadata", 21 "InstallType", 22 "Language", 23 "get_available_connectors", 24 "get_connector_metadata", 25]
78class ConnectorMetadata(BaseModel): 79 """Metadata for a connector.""" 80 81 name: str 82 """Connector name. For example, "source-google-sheets".""" 83 84 latest_available_version: str | None 85 """The latest available version of the connector.""" 86 87 pypi_package_name: str | None 88 """The name of the PyPI package for the connector, if it exists.""" 89 90 language: Language | None 91 """The language of the connector.""" 92 93 install_types: set[InstallType] 94 """The supported install types for the connector.""" 95 96 suggested_streams: list[str] | None = None 97 """A list of suggested streams for the connector, if available.""" 98 99 @property 100 def default_install_type(self) -> InstallType: 101 """Return the default install type for the connector.""" 102 if self.language == Language.MANIFEST_ONLY and InstallType.YAML in self.install_types: 103 return InstallType.YAML 104 105 if InstallType.PYTHON in self.install_types: 106 return InstallType.PYTHON 107 108 # Else: Java or Docker 109 return InstallType.DOCKER
Metadata for a connector.
The latest available version of the connector.
The name of the PyPI package for the connector, if it exists.
A list of suggested streams for the connector, if available.
99 @property 100 def default_install_type(self) -> InstallType: 101 """Return the default install type for the connector.""" 102 if self.language == Language.MANIFEST_ONLY and InstallType.YAML in self.install_types: 103 return InstallType.YAML 104 105 if InstallType.PYTHON in self.install_types: 106 return InstallType.PYTHON 107 108 # Else: Java or Docker 109 return InstallType.DOCKER
Return the default install type for the connector.
49class InstallType(str, Enum): 50 """The type of installation for a connector.""" 51 52 YAML = "yaml" 53 """Manifest-only connectors that can be run without Docker.""" 54 PYTHON = "python" 55 """Python-based connectors available via PyPI.""" 56 DOCKER = "docker" 57 """Docker-based connectors (returns all connectors for backward compatibility).""" 58 JAVA = "java" 59 """Java-based connectors.""" 60 61 INSTALLABLE = "installable" 62 """Connectors installable in the current environment (environment-sensitive). 63 64 Returns all connectors if Docker is installed, otherwise only Python and YAML. 65 """ 66 ANY = "any" 67 """All connectors in the registry (environment-independent)."""
The type of installation for a connector.
Docker-based connectors (returns all connectors for backward compatibility).
Connectors installable in the current environment (environment-sensitive).
Returns all connectors if Docker is installed, otherwise only Python and YAML.
70class Language(str, Enum): 71 """The language of a connector.""" 72 73 PYTHON = InstallType.PYTHON.value 74 JAVA = InstallType.JAVA.value 75 MANIFEST_ONLY = _MANIFEST_ONLY_LANGUAGE
The language of a connector.
251def get_available_connectors( 252 install_type: InstallType | str | None = InstallType.INSTALLABLE, 253) -> list[str]: 254 """Return a list of all available connectors. 255 256 Connectors will be returned in alphabetical order, with the standard prefix "source-". 257 258 Args: 259 install_type: The type of installation for the connector. 260 Defaults to `InstallType.INSTALLABLE`. 261 """ 262 if install_type is None or install_type == InstallType.INSTALLABLE: 263 # Filter for installable connectors (default behavior). 264 if is_docker_installed(): 265 logger.info("Docker is detected. Returning all connectors.") 266 return sorted(_get_registry_cache().keys()) 267 268 logger.info("Docker was not detected. Returning only Python and Manifest-only connectors.") 269 return sorted( 270 [ 271 connector_name 272 for connector_name, conn_info in _get_registry_cache().items() 273 if conn_info.language in {Language.PYTHON, Language.MANIFEST_ONLY} 274 ] 275 ) 276 277 if not isinstance(install_type, InstallType): 278 install_type = InstallType(install_type) 279 280 if install_type == InstallType.PYTHON: 281 return sorted( 282 connector_name 283 for connector_name, conn_info in _get_registry_cache().items() 284 if conn_info.pypi_package_name is not None 285 ) 286 287 if install_type == InstallType.JAVA: 288 warnings.warn( 289 message="Java connectors are not yet supported.", 290 stacklevel=2, 291 ) 292 return sorted( 293 connector_name 294 for connector_name, conn_info in _get_registry_cache().items() 295 if conn_info.language == Language.JAVA 296 ) 297 298 if install_type in {InstallType.DOCKER, InstallType.ANY}: 299 return sorted(_get_registry_cache().keys()) 300 301 if install_type == InstallType.YAML: 302 return sorted( 303 conn.name 304 for conn in _get_registry_cache().values() 305 if InstallType.YAML in conn.install_types 306 ) 307 308 # pragma: no cover # Should never be reached. 309 raise exc.PyAirbyteInputError( 310 message="Invalid install type.", 311 context={ 312 "install_type": install_type, 313 }, 314 )
Return a list of all available connectors.
Connectors will be returned in alphabetical order, with the standard prefix "source-".
Arguments:
- install_type: The type of installation for the connector.
Defaults to
InstallType.INSTALLABLE.
221def get_connector_metadata(name: str) -> ConnectorMetadata | None: 222 """Check the cache for the connector. 223 224 If the cache is empty, populate by calling update_cache. 225 """ 226 registry_url = _get_registry_url() 227 228 if _is_registry_disabled(registry_url): 229 return None 230 231 cache = copy(_get_registry_cache()) 232 233 if not cache: 234 raise exc.PyAirbyteInternalError( 235 message="Connector registry could not be loaded.", 236 context={ 237 "registry_url": _get_registry_url(), 238 }, 239 ) 240 if name not in cache: 241 raise exc.AirbyteConnectorNotRegisteredError( 242 connector_name=name, 243 context={ 244 "registry_url": _get_registry_url(), 245 "available_connectors": get_available_connectors(), 246 }, 247 ) 248 return cache[name]
Check the cache for the connector.
If the cache is empty, populate by calling update_cache.