Skip to main content

gc-batch

A command-line interface and Python client for managing Google Cloud Batch jobs, with support for job creation, monitoring, logging, GCS bucket mounts, local SSD storage, and filtering by labels.

Installation

pip install gc-batch

Or, for development, using uv:

git clone https://github.com/empirico-oss/gc-batch.git
cd gc-batch
uv sync

Requires Python 3.10 or newer, and credentials for a Google Cloud project with the Batch API enabled (gcloud auth application-default login).

Quick start

# Create a job
gc-batch --project-id my-project create \
  --job-name my-first-job \
  --docker-image gcr.io/my-project/my-image:latest \
  --command "python /app/main.py"

# List jobs, or just your own
gc-batch --project-id my-project list-jobs
gc-batch --project-id my-project list-my-jobs

# Check status and read logs
gc-batch --project-id my-project status --job-name my-first-job-1234567890
gc-batch --project-id my-project logs --job-name my-first-job-1234567890

The project is resolved from --project-id, then $GOOGLE_PROJECT, then the default_project_id setting. If none is set, the command exits with an error rather than guessing.

Use as a Python library

The same functionality is importable, so scripts, notebooks, and orchestration code can submit and monitor jobs without shelling out to the CLI:

import time

from gc_batch import BatchClientConfig, BatchJobConfig, GCBatchClient, JobRequest
from gc_batch.utils import is_job_finished

client = GCBatchClient(BatchClientConfig(project_id="my-project", location="us-central1"))

job = client.create_job(
    JobRequest(
        job_name="my-first-job",
        docker_image="gcr.io/my-project/my-image:latest",
        command="python /app/main.py",
        config=BatchJobConfig(
            machine_type="n2-standard-4",
            boot_disk_type="pd-balanced",
            input_bucket="my-bucket/datasets",
            output_bucket="my-bucket/results",
        ),
        labels={"team": "data-science"},
    )
)

# create_job timestamps the name, so read the submitted one off the job
short_name = job.name.split("/")[-1]

while not is_job_finished(job := client.get_job(short_name)):
    time.sleep(30)

print(job.status.state.name)
if job.status.state.name == "FAILED":
    print(client.get_failure_message(job))
    print(client.get_cloud_logging_url(job, severity="ERROR"))

Listing, cancelling, and log retrieval are all available too:

jobs = client.list_jobs(labels={"team": "data-science"}, status="RUNNING")
client.cancel_job(job.name)  # full resource path, not the short name

# Logs, from Cloud Logging or from the bucket when the job used logs_bucket
client.batch_logging.print_logs_for_job(job)
client.gcs_logging.print_logs_for_job(job)

See the Python API guide for job profiles, mounts, local SSD, settings, fan-out, and error handling.

Configuration

Values that differ between deployments — the job-name prefix, the created-using label, and named job profiles — are resolved in this order, highest precedence first:

  1. explicit arguments
  2. GC_BATCH_* environment variables
  3. a TOML config file (--config-file, $GC_BATCH_CONFIG_FILE, ./gc-batch.toml, or $XDG_CONFIG_HOME/gc-batch/config.toml)
  4. neutral defaults

Restricted VPC environments

gc-batch ships a built-in all-of-us job profile for the All of Us Researcher Workbench, which runs jobs inside a restricted VPC:

gc-batch --project-id my-project create \
  --job-profile all-of-us \
  --job-name my-job \
  --docker-image gcr.io/my-project/my-image:latest \
  --command "python /app/main.py"

You can define additional profiles in the config file. See the Configuration guide.

Documentation

Full documentation: https://empirico-oss.github.io/gc-batch/stable/

Contributing

See CONTRIBUTING.md. Security issues should be reported per SECURITY.md.

License

MIT — see LICENSE.

Metadata

Release files for gc-batch 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gc-batch 0.2.5
File Size Uploaded Provenance Actions
gc_batch-0.2.5.tar.gz 65.5 kB With provenance Details for gc_batch-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gc-batch 0.2.5
File Interpreter ABI Platform Actions
gc_batch-0.2.5-py3-none-any.whl Python 3 none any Details for gc_batch-0.2.5-py3-none-any.whl

Total release size: 115.9 kB

Release files / gc_batch-0.2.5.tar.gz

Download URL gc_batch-0.2.5.tar.gz
Size 65.5 kB
Tags Source
SHA-256 checksum
How to use checksums
67f0186ef9415fc597e57dea232fa120ac98bfce1692e9e77fcb64f5d1628c75
BLAKE2b-256 checksum
How to use checksums
d05fcccf837bf12bcbbede9cedc9a7eb0c71a3ad96e7ff1f742e317db835d1e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / gc_batch-0.2.5-py3-none-any.whl

Download URL gc_batch-0.2.5-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79e1704cd7b5c35f176f509600e349d40c77d4f66213e2452255913c5b96af29
BLAKE2b-256 checksum
How to use checksums
88c09f373aba123f7b4e792e30bf41ad670d89256f14d773cc5c673ae4542a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for gc-batch 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gc_batch-0.2.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page