Python client library for managing BigQuery Data Transfer Service operations and scheduling data transfers from partner SaaS applications.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Management and monitoring of individual transfer executions, including manual execution, status monitoring, log retrieval, and run lifecycle operations.
Returns information about the particular transfer run.
def get_transfer_run(
self,
request: Optional[Union[GetTransferRunRequest, dict]] = None,
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> TransferRun:
"""
Returns information about the particular transfer run.
Args:
request: The request object containing run name.
name: Required. The field will contain name of the resource requested.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
Returns:
TransferRun: The requested transfer run.
"""Deletes the specified transfer run.
def delete_transfer_run(
self,
request: Optional[Union[DeleteTransferRunRequest, dict]] = None,
*,
name: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> None:
"""
Deletes the specified transfer run.
Args:
request: The request object containing run name.
name: Required. The field will contain name of the resource requested.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
"""Returns information about running and completed transfer runs.
def list_transfer_runs(
self,
request: Optional[Union[ListTransferRunsRequest, dict]] = None,
*,
parent: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> pagers.ListTransferRunsPager:
"""
Returns information about running and completed transfer runs.
Args:
request: The request object containing parent transfer config.
parent: Required. Name of transfer configuration for which transfer runs should be retrieved.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
Returns:
ListTransferRunsResponse: The list of transfer runs.
"""Start manual transfer runs to be executed now with schedule_time equal to current time.
def start_manual_transfer_runs(
self,
request: Optional[Union[StartManualTransferRunsRequest, dict]] = None,
*,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> StartManualTransferRunsResponse:
"""
Start manual transfer runs to be executed now with schedule_time equal to current time.
Args:
request: The request object containing manual run parameters.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
Returns:
StartManualTransferRunsResponse: The response containing created runs.
"""Creates transfer runs for a time range.
def schedule_transfer_runs(
self,
request: Optional[Union[ScheduleTransferRunsRequest, dict]] = None,
*,
parent: Optional[str] = None,
start_time: Optional[timestamp_pb2.Timestamp] = None,
end_time: Optional[timestamp_pb2.Timestamp] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> ScheduleTransferRunsResponse:
"""
Creates transfer runs for a time range.
Args:
request: The request object containing schedule parameters.
parent: Required. Transfer configuration name.
start_time: Required. Start time of the range of transfer runs.
end_time: Required. End time of the range of transfer runs.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
Returns:
ScheduleTransferRunsResponse: The response containing scheduled runs.
"""Returns log messages for the transfer run.
def list_transfer_logs(
self,
request: Optional[Union[ListTransferLogsRequest, dict]] = None,
*,
parent: Optional[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
) -> pagers.ListTransferLogsPager:
"""
Returns user facing log messages for the data transfer run.
Args:
request: The request object containing run name.
parent: Required. Transfer run name.
retry: Designation of what errors should be retried.
timeout: The timeout for this request.
metadata: Strings which should be sent along with the request.
Returns:
ListTransferLogsResponse: The list of transfer log messages.
"""class GetTransferRunRequest:
"""
A request to get information about a transfer run.
Attributes:
name (str): Required. The field will contain name of the resource requested.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}/runs/{run_id}
"""
name: str
class DeleteTransferRunRequest:
"""
A request to delete a transfer run.
Attributes:
name (str): Required. The field will contain name of the resource requested.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}/runs/{run_id}
"""
name: str
class ListTransferRunsRequest:
"""
A request message for ListTransferRuns.
Attributes:
parent (str): Required. Name of transfer configuration for which transfer runs should be retrieved.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}
states (Sequence[TransferState]): When specified, only transfer runs with requested states are returned.
page_token (str): Pagination token.
page_size (int): Page size. The default page size is the maximum value of 1000 results.
run_attempt (RunAttempt): Indicates how run attempts are to be pulled.
"""
parent: str
states: Sequence[TransferState]
page_token: str
page_size: int
run_attempt: RunAttempt
class RunAttempt(proto.Enum):
"""Represents which runs should be pulled."""
RUN_ATTEMPT_UNSPECIFIED = 0
LATEST = 1class StartManualTransferRunsRequest:
"""
A request to start manual transfer runs.
Attributes:
parent (str): Required. Transfer configuration name.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}
requested_time_range (TimeRange): The requested time range for the transfer run.
requested_run_time (Timestamp): The requested run time for the transfer run.
"""
parent: str
requested_time_range: TimeRange
requested_run_time: timestamp_pb2.Timestamp
class TimeRange(proto.Message):
"""
A specification for a time range for transfer runs.
Attributes:
start_time (Timestamp): Start time of the range of transfer runs.
end_time (Timestamp): End time of the range of transfer runs.
"""
start_time: timestamp_pb2.Timestamp
end_time: timestamp_pb2.Timestampclass ScheduleTransferRunsRequest:
"""
A request to schedule transfer runs for a time range.
Attributes:
parent (str): Required. Transfer configuration name.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}
start_time (Timestamp): Required. Start time of the range of transfer runs.
end_time (Timestamp): Required. End time of the range of transfer runs.
"""
parent: str
start_time: timestamp_pb2.Timestamp
end_time: timestamp_pb2.Timestamp
class ListTransferLogsRequest:
"""
A request message for ListTransferLogs.
Attributes:
parent (str): Required. Transfer run name.
Format: projects/{project_id}/locations/{location_id}/transferConfigs/{config_id}/runs/{run_id}
page_token (str): Pagination token.
page_size (int): Page size. The default page size is the maximum value of 1000 results.
message_types (Sequence[MessageType]): Message types to return.
"""
parent: str
page_token: str
page_size: int
message_types: Sequence[MessageType]class ListTransferRunsResponse:
"""
The returned list of pipelines in the project.
Attributes:
transfer_runs (Sequence[TransferRun]): Output only. The stored pipeline transfer runs.
next_page_token (str): Output only. The next-pagination token.
"""
transfer_runs: Sequence[TransferRun]
next_page_token: str
class StartManualTransferRunsResponse:
"""
A response to start manual transfer runs.
Attributes:
runs (Sequence[TransferRun]): The transfer runs that were created.
"""
runs: Sequence[TransferRun]
class ScheduleTransferRunsResponse:
"""
A response to schedule transfer runs for a time range.
Attributes:
runs (Sequence[TransferRun]): The transfer runs that were scheduled.
"""
runs: Sequence[TransferRun]
class ListTransferLogsResponse:
"""
The returned list transfer run messages.
Attributes:
transfer_messages (Sequence[TransferMessage]): Output only. The stored pipeline transfer messages.
next_page_token (str): Output only. The next-pagination token.
"""
transfer_messages: Sequence[TransferMessage]
next_page_token: strfrom google.cloud import bigquery_datatransfer
client = bigquery_datatransfer.DataTransferServiceClient()
# List all runs for a transfer config
parent = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}"
response = client.list_transfer_runs(parent=parent)
print("Transfer runs:")
for run in response:
print(f" Run ID: {run.name}")
print(f" State: {run.state}")
print(f" Schedule Time: {run.schedule_time}")
print(f" Start Time: {run.start_time}")
print(f" End Time: {run.end_time}")
print(f" Error Status: {run.error_status}")
# List runs with specific states only
from google.cloud.bigquery_datatransfer_v1 import TransferState
response = client.list_transfer_runs(
parent=parent,
states=[TransferState.FAILED, TransferState.SUCCEEDED]
)
print("Completed runs (success/failure):")
for run in response:
print(f" {run.name}: {run.state}")from google.cloud import bigquery_datatransfer
client = bigquery_datatransfer.DataTransferServiceClient()
# Get specific transfer run
run_name = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}/runs/{run_id}"
run = client.get_transfer_run(name=run_name)
print(f"Transfer Run: {run.name}")
print(f"State: {run.state}")
print(f"Data Source ID: {run.data_source_id}")
print(f"Destination Dataset ID: {run.destination_dataset_id}")
print(f"Schedule Time: {run.schedule_time}")
print(f"Start Time: {run.start_time}")
print(f"End Time: {run.end_time}")
print(f"User ID: {run.user_id}")
if run.error_status and run.error_status.code != 0:
print(f"Error: {run.error_status.message}")from google.cloud import bigquery_datatransfer
from google.protobuf import timestamp_pb2
import datetime
client = bigquery_datatransfer.DataTransferServiceClient()
# Start manual run with specific time
now = datetime.datetime.now(datetime.timezone.utc)
requested_time = timestamp_pb2.Timestamp()
requested_time.FromDatetime(now)
parent = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}"
request = {
"parent": parent,
"requested_run_time": requested_time
}
response = client.start_manual_transfer_runs(request=request)
print("Started manual transfer runs:")
for run in response.runs:
print(f" Run ID: {run.name}")
print(f" State: {run.state}")
print(f" Schedule Time: {run.schedule_time}")from google.cloud import bigquery_datatransfer
from google.protobuf import timestamp_pb2
import datetime
client = bigquery_datatransfer.DataTransferServiceClient()
# Schedule runs for a week
start_date = datetime.datetime(2024, 1, 1, tzinfo=datetime.timezone.utc)
end_date = datetime.datetime(2024, 1, 7, tzinfo=datetime.timezone.utc)
start_time = timestamp_pb2.Timestamp()
start_time.FromDatetime(start_date)
end_time = timestamp_pb2.Timestamp()
end_time.FromDatetime(end_date)
parent = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}"
response = client.schedule_transfer_runs(
parent=parent,
start_time=start_time,
end_time=end_time
)
print(f"Scheduled {len(response.runs)} transfer runs:")
for run in response.runs:
print(f" Run ID: {run.name}")
print(f" Schedule Time: {run.schedule_time}")from google.cloud import bigquery_datatransfer
client = bigquery_datatransfer.DataTransferServiceClient()
# Get logs for a specific run
parent = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}/runs/{run_id}"
response = client.list_transfer_logs(parent=parent)
print("Transfer run logs:")
for message in response.transfer_messages:
print(f" [{message.message_time}] {message.severity}: {message.message_text}")from google.cloud import bigquery_datatransfer
client = bigquery_datatransfer.DataTransferServiceClient()
# Delete specific transfer run
run_name = f"projects/{project_id}/locations/{location}/transferConfigs/{config_id}/runs/{run_id}"
client.delete_transfer_run(name=run_name)
print(f"Deleted transfer run: {run_name}")Install with Tessl CLI
npx tessl i tessl/pypi-google-cloud-bigquery-datatransfer