As of January 1, 2020 this library no longer supports Python 2 on the latest released version.
Library versions released prior to that date will continue to be available. For more information please
visit Python 2 support on Google Cloud.
Managing Jobs¶
Jobs describe actions performed on data in BigQuery tables:
Load data into a table
Run a query against data in one or more tables
Extract data from a table
Copy a table
Listing jobs¶
List jobs for a project with the
list_jobs()
method:
from google.cloud import bigquery
import datetime
# Construct a BigQuery client object.
client = bigquery.Client()
# List the 10 most recent jobs in reverse chronological order.
# Omit the max_results parameter to list jobs from the past 6 months.
print("Last 10 jobs:")
for job in client.list_jobs(max_results=10): # API request(s)
print("{}".format(job.job_id))
# The following are examples of additional optional parameters:
# Use min_creation_time and/or max_creation_time to specify a time window.
print("Jobs from the last ten minutes:")
ten_mins_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=10)
for job in client.list_jobs(min_creation_time=ten_mins_ago):
print("{}".format(job.job_id))
# Use all_users to include jobs run by all users in the project.
print("Last 10 jobs run by all users:")
for job in client.list_jobs(max_results=10, all_users=True):
print("{} run by user: {}".format(job.job_id, job.user_email))
# Use state_filter to filter by job state.
print("Last 10 jobs done:")
for job in client.list_jobs(max_results=10, state_filter="DONE"):
print("{}".format(job.job_id))