Airbyte (dagster-airbyte)

This library provides a Dagster integration with Airbyte.

Ops

dagster_airbyte.airbyte_sync_op = <dagster.core.definitions.op_definition.OpDefinition object>[source]

Config Schema:
connection_id (String)

The Airbyte Connection ID that this op will sync. You can retrieve this value from the “Connections” tab of a given connector in the Airbyte UI.

poll_interval (Float, optional)

The time (in seconds) that will be waited between successive polls.

Default Value: 10

poll_timeout (Union[Float, None], optional)

The maximum time that will waited before this operation is timed out. By default, this will never time out.

Default Value: None

yield_materializations (Bool, optional)

If True, materializations corresponding to the results of the Airbyte sync will be yielded when the op executes.

Default Value: True

asset_key_prefix (List[String], optional)

If provided and yield_materializations is True, these components will be used to prefix the generated asset keys.

Default Value: [‘airbyte’]

Executes a Airbyte job sync for a given connection_id, and polls until that sync completes, raising an error if it is unsuccessful. It outputs a AirbyteOutput which contains the job details for a given connection_id.

It requires the use of the airbyte_resource, which allows it to communicate with the Airbyte API.

Examples:

from dagster import job
from dagster_airbyte import airbyte_resource, airbyte_sync_op

my_airbyte_resource = airbyte_resource.configured(
    {
        "host": {"env": "AIRBYTE_HOST"},
        "port": {"env": "AIRBYTE_PORT"},
    }
)

sync_foobar = airbyte_sync_op.configured({"connection_id": "foobar"}, name="sync_foobar")

@job(resource_defs={"airbyte": my_airbyte_resource})
def my_simple_airbyte_job():
    sync_foobar()

@job(resource_defs={"airbyte": my_airbyte_resource})
def my_composed_airbyte_job():
    final_foobar_state = sync_foobar(start_after=some_op())
    other_op(final_foobar_state)

Resources

dagster_airbyte.airbyte_resource ResourceDefinition[source]

Config Schema:
host (dagster.StringSource)

The Airbyte Server Address.

port (dagster.StringSource, optional)

Port for the Airbyte Server.

use_https (Bool, optional)

Use https to connect in Airbyte Server.

Default Value: False

request_max_retries (Int, optional)

The maximum number of times requests to the Airbyte API should be retried before failing.

Default Value: 3

request_retry_delay (Float, optional)

Time (in seconds) to wait between each request retry.

Default Value: 0.25

This resource allows users to programatically interface with the Airbyte REST API to launch syncs and monitor their progress. This currently implements only a subset of the functionality exposed by the API.

For a complete set of documentation on the Airbyte REST API, including expected response JSON schema, see the Airbyte API Docs.

To configure this resource, we recommend using the configured method.

Examples:

from dagster import job
from dagster_airbyte import airbyte_resource

my_airbyte_resource = airbyte_resource.configured(
    {
        "host": {"env": "AIRBYTE_HOST"},
        "port": {"env": "AIRBYTE_PORT"},
    }
)

@job(resource_defs={"airbyte":my_airbyte_resource})
def my_airbyte_job():
    ...
class dagster_airbyte.AirbyteResource(host, port, use_https, request_max_retries=3, request_retry_delay=0.25, log=<Logger dagster.builtin (DEBUG)>)[source]

This class exposes methods on top of the Airbyte REST API.

make_request(endpoint, data)[source]

Creates and sends a request to the desired Airbyte REST API endpoint.

Parameters
  • endpoint (str) – The Airbyte API endpoint to send this request to.

  • data (Optional[str]) – JSON-formatted data string to be included in the request.

Returns

Parsed json data from the response to this request

Return type

Optional[Dict[str, Any]]

sync_and_poll(connection_id, poll_interval=10, poll_timeout=None)[source]

Initializes a sync operation for the given connector, and polls until it completes.

Parameters
  • connection_id (str) – The Airbyte Connector ID. You can retrieve this value from the “Connection” tab of a given connection in the Arbyte UI.

  • poll_interval (float) – The time (in seconds) that will be waited between successive polls.

  • poll_timeout (float) – The maximum time that will waited before this operation is timed out. By default, this will never time out.

Returns

Details of the sync job.

Return type

AirbyteOutput

Assets

dagster_airbyte.build_airbyte_assets(connection_id, destination_tables, asset_key_prefix=None)[source]

Builds a set of assets representing the tables created by an Airbyte sync operation.

Parameters
  • connection_id (str) – The Airbyte Connection ID that this op will sync. You can retrieve this value from the “Connections” tab of a given connector in the Airbyte UI.

  • destination_tables (List[str]) – The names of the tables that you want to be represented in the Dagster asset graph for this sync. This will generally map to the name of the stream in Airbyte, unless a stream prefix has been specified in Airbyte.

  • asset_key_prefix (Optional[List[str]]) – A prefix for the asset keys inside this asset. If left blank, assets will have a key of AssetKey([table_name]).