airbyte_cdk.models.connector_metadata

Models to represent the structure of a metadata.yaml file.

  1"""Models to represent the structure of a `metadata.yaml` file."""
  2
  3from __future__ import annotations
  4
  5from enum import Enum
  6from pathlib import Path
  7
  8import yaml
  9from pydantic import BaseModel, Field
 10
 11
 12class ConnectorLanguage(str, Enum):
 13    """Connector implementation language."""
 14
 15    PYTHON = "python"
 16    JAVA = "java"
 17    LOW_CODE = "low-code"
 18    MANIFEST_ONLY = "manifest-only"
 19    UNKNOWN = "unknown"
 20
 21
 22class ConnectorBuildOptions(BaseModel):
 23    """Connector build options from metadata.yaml."""
 24
 25    model_config = {"extra": "allow"}
 26
 27    baseImage: str | None = Field(
 28        None,
 29        description="Base image to use for building the connector",
 30    )
 31    path: str | None = Field(
 32        None,
 33        description="Path to the connector code within the repository",
 34    )
 35
 36
 37class SuggestedStreams(BaseModel):
 38    """Suggested streams from metadata.yaml."""
 39
 40    streams: list[str] = Field(
 41        default=[],
 42        description="List of suggested streams for the connector",
 43    )
 44
 45
 46class ConnectorMetadata(BaseModel):
 47    """Connector metadata from metadata.yaml."""
 48
 49    model_config = {"extra": "allow"}
 50
 51    dockerRepository: str = Field(..., description="Docker repository for the connector image")
 52    dockerImageTag: str = Field(..., description="Docker image tag for the connector")
 53
 54    tags: list[str] = Field(
 55        default=[],
 56        description="List of tags for the connector",
 57    )
 58
 59    suggestedStreams: SuggestedStreams | None = Field(
 60        default=None,
 61        description="Suggested streams for the connector",
 62    )
 63
 64    @property
 65    def language(self) -> ConnectorLanguage:
 66        """Get the connector language."""
 67        for tag in self.tags:
 68            if tag.startswith("language:"):
 69                language = tag.split(":", 1)[1]
 70                if language == "python":
 71                    return ConnectorLanguage.PYTHON
 72                elif language == "java":
 73                    return ConnectorLanguage.JAVA
 74                elif language == "low-code":
 75                    return ConnectorLanguage.LOW_CODE
 76                elif language == "manifest-only":
 77                    return ConnectorLanguage.MANIFEST_ONLY
 78
 79        return ConnectorLanguage.UNKNOWN
 80
 81    connectorBuildOptions: ConnectorBuildOptions | None = Field(
 82        None, description="Options for building the connector"
 83    )
 84
 85
 86class MetadataFile(BaseModel):
 87    """Represents the structure of a metadata.yaml file."""
 88
 89    model_config = {"extra": "allow"}
 90
 91    data: ConnectorMetadata = Field(..., description="Connector metadata")
 92
 93    @classmethod
 94    def from_file(
 95        cls,
 96        file_path: Path,
 97    ) -> MetadataFile:
 98        """Load metadata from a YAML file."""
 99        if not file_path.exists():
100            raise FileNotFoundError(f"Metadata file not found: {file_path!s}")
101
102        metadata_content = file_path.read_text()
103        metadata_dict = yaml.safe_load(metadata_content)
104
105        if not metadata_dict or "data" not in metadata_dict:
106            raise ValueError(
107                "Invalid metadata format: missing 'data' field in YAML file '{file_path!s}'"
108            )
109
110        metadata_file = MetadataFile.model_validate(metadata_dict)
111        return metadata_file
class ConnectorLanguage(builtins.str, enum.Enum):
13class ConnectorLanguage(str, Enum):
14    """Connector implementation language."""
15
16    PYTHON = "python"
17    JAVA = "java"
18    LOW_CODE = "low-code"
19    MANIFEST_ONLY = "manifest-only"
20    UNKNOWN = "unknown"

Connector implementation language.

PYTHON = <ConnectorLanguage.PYTHON: 'python'>
JAVA = <ConnectorLanguage.JAVA: 'java'>
LOW_CODE = <ConnectorLanguage.LOW_CODE: 'low-code'>
MANIFEST_ONLY = <ConnectorLanguage.MANIFEST_ONLY: 'manifest-only'>
UNKNOWN = <ConnectorLanguage.UNKNOWN: 'unknown'>
class ConnectorBuildOptions(pydantic.main.BaseModel):
23class ConnectorBuildOptions(BaseModel):
24    """Connector build options from metadata.yaml."""
25
26    model_config = {"extra": "allow"}
27
28    baseImage: str | None = Field(
29        None,
30        description="Base image to use for building the connector",
31    )
32    path: str | None = Field(
33        None,
34        description="Path to the connector code within the repository",
35    )

Connector build options from metadata.yaml.

model_config = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

baseImage: str | None
path: str | None
class SuggestedStreams(pydantic.main.BaseModel):
38class SuggestedStreams(BaseModel):
39    """Suggested streams from metadata.yaml."""
40
41    streams: list[str] = Field(
42        default=[],
43        description="List of suggested streams for the connector",
44    )

Suggested streams from metadata.yaml.

streams: list[str]
model_config: ClassVar[pydantic.config.ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class ConnectorMetadata(pydantic.main.BaseModel):
47class ConnectorMetadata(BaseModel):
48    """Connector metadata from metadata.yaml."""
49
50    model_config = {"extra": "allow"}
51
52    dockerRepository: str = Field(..., description="Docker repository for the connector image")
53    dockerImageTag: str = Field(..., description="Docker image tag for the connector")
54
55    tags: list[str] = Field(
56        default=[],
57        description="List of tags for the connector",
58    )
59
60    suggestedStreams: SuggestedStreams | None = Field(
61        default=None,
62        description="Suggested streams for the connector",
63    )
64
65    @property
66    def language(self) -> ConnectorLanguage:
67        """Get the connector language."""
68        for tag in self.tags:
69            if tag.startswith("language:"):
70                language = tag.split(":", 1)[1]
71                if language == "python":
72                    return ConnectorLanguage.PYTHON
73                elif language == "java":
74                    return ConnectorLanguage.JAVA
75                elif language == "low-code":
76                    return ConnectorLanguage.LOW_CODE
77                elif language == "manifest-only":
78                    return ConnectorLanguage.MANIFEST_ONLY
79
80        return ConnectorLanguage.UNKNOWN
81
82    connectorBuildOptions: ConnectorBuildOptions | None = Field(
83        None, description="Options for building the connector"
84    )

Connector metadata from metadata.yaml.

model_config = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

dockerRepository: str
dockerImageTag: str
tags: list[str]
suggestedStreams: SuggestedStreams | None
language: ConnectorLanguage
65    @property
66    def language(self) -> ConnectorLanguage:
67        """Get the connector language."""
68        for tag in self.tags:
69            if tag.startswith("language:"):
70                language = tag.split(":", 1)[1]
71                if language == "python":
72                    return ConnectorLanguage.PYTHON
73                elif language == "java":
74                    return ConnectorLanguage.JAVA
75                elif language == "low-code":
76                    return ConnectorLanguage.LOW_CODE
77                elif language == "manifest-only":
78                    return ConnectorLanguage.MANIFEST_ONLY
79
80        return ConnectorLanguage.UNKNOWN

Get the connector language.

connectorBuildOptions: ConnectorBuildOptions | None
class MetadataFile(pydantic.main.BaseModel):
 87class MetadataFile(BaseModel):
 88    """Represents the structure of a metadata.yaml file."""
 89
 90    model_config = {"extra": "allow"}
 91
 92    data: ConnectorMetadata = Field(..., description="Connector metadata")
 93
 94    @classmethod
 95    def from_file(
 96        cls,
 97        file_path: Path,
 98    ) -> MetadataFile:
 99        """Load metadata from a YAML file."""
100        if not file_path.exists():
101            raise FileNotFoundError(f"Metadata file not found: {file_path!s}")
102
103        metadata_content = file_path.read_text()
104        metadata_dict = yaml.safe_load(metadata_content)
105
106        if not metadata_dict or "data" not in metadata_dict:
107            raise ValueError(
108                "Invalid metadata format: missing 'data' field in YAML file '{file_path!s}'"
109            )
110
111        metadata_file = MetadataFile.model_validate(metadata_dict)
112        return metadata_file

Represents the structure of a metadata.yaml file.

model_config = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

@classmethod
def from_file( cls, file_path: pathlib.Path) -> MetadataFile:
 94    @classmethod
 95    def from_file(
 96        cls,
 97        file_path: Path,
 98    ) -> MetadataFile:
 99        """Load metadata from a YAML file."""
100        if not file_path.exists():
101            raise FileNotFoundError(f"Metadata file not found: {file_path!s}")
102
103        metadata_content = file_path.read_text()
104        metadata_dict = yaml.safe_load(metadata_content)
105
106        if not metadata_dict or "data" not in metadata_dict:
107            raise ValueError(
108                "Invalid metadata format: missing 'data' field in YAML file '{file_path!s}'"
109            )
110
111        metadata_file = MetadataFile.model_validate(metadata_dict)
112        return metadata_file

Load metadata from a YAML file.