{"id":4026,"library":"google-cloud-scheduler","title":"Google Cloud Scheduler Client Library","description":"The `google-cloud-scheduler` Python client library allows developers to programmatically create, manage, and delete Cloud Scheduler jobs. Cloud Scheduler is a fully managed cron job service that enables you to schedule virtually any asynchronous task, such as invoking HTTP endpoints, publishing messages to Pub/Sub topics, or triggering App Engine applications. The library is actively maintained by Google, with frequent releases, and is currently at version 2.19.0.","status":"active","version":"2.19.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-scheduler","tags":["google cloud","scheduler","cron","automation","serverless","task scheduling"],"install":[{"cmd":"pip install google-cloud-scheduler","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required Python version as specified by the package metadata.","package":"Python","version":">=3.9","optional":false}],"imports":[{"note":"The client class is nested under the `scheduler_v1` module, representing the v1 API.","wrong":"from google.cloud.scheduler import CloudSchedulerClient","symbol":"CloudSchedulerClient","correct":"from google.cloud import scheduler_v1"},{"note":"Use this import for the beta version of the API. Generally, `v1` is preferred for production unless specific beta features are required.","symbol":"CloudSchedulerClient (v1beta1)","correct":"from google.cloud import scheduler_v1beta1"}],"quickstart":{"code":"import os\nfrom google.cloud import scheduler_v1\n\nproject_id = os.environ.get('GCP_PROJECT_ID', 'your-project-id')\nlocation_id = os.environ.get('GCP_LOCATION_ID', 'us-central1') # e.g., 'us-central1'\njob_name = os.environ.get('SCHEDULER_JOB_NAME', 'my-scheduled-job')\ntarget_url = os.environ.get('SCHEDULER_TARGET_URL', 'https://your-http-endpoint.cloudfunctions.net/myFunction')\n\n# Initialize a client\nclient = scheduler_v1.CloudSchedulerClient()\n\n# Construct the full resource name of the parent of the job\nparent = client.location_path(project_id, location_id)\n\n# Construct the job body\njob = scheduler_v1.Job()\njob.name = client.job_path(project_id, location_id, job_name)\njob.description = 'My first Cloud Scheduler job (Python client)'\njob.schedule = '0 * * * *'  # Run every hour\njob.time_zone = 'America/Los_Angeles'\n\n# Configure an HTTP target\nhttp_target = scheduler_v1.HttpTarget()\nhttp_target.uri = target_url\nhttp_target.http_method = scheduler_v1.HttpMethod.POST\njob.http_target = http_target\n\n# Create the job\ntry:\n    response = client.create_job(parent=parent, job=job)\n    print(f'Created job: {response.name}')\nexcept Exception as e:\n    print(f'Error creating job: {e}')\n\n# To delete the job (uncomment to run)\n# try:\n#     client.delete_job(name=response.name)\n#     print(f'Deleted job: {response.name}')\n# except Exception as e:\n#     print(f'Error deleting job: {e}')\n","lang":"python","description":"This quickstart demonstrates how to create a simple Cloud Scheduler job that triggers an HTTP endpoint every hour using the `scheduler_v1` API. Ensure your `GCP_PROJECT_ID`, `GCP_LOCATION_ID`, `SCHEDULER_JOB_NAME`, and `SCHEDULER_TARGET_URL` environment variables are set or replaced in the code. Authentication is handled automatically via Application Default Credentials if running in a Google Cloud environment or with `gcloud auth application-default login` locally."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or higher. For example, using `pyenv` or updating your system's Python installation.","message":"The library explicitly requires Python 3.9 or newer. Running on older Python versions (3.8 or below) will result in installation failures or runtime errors.","severity":"breaking","affected_versions":"<2.19.0 (earlier versions might support older Python, but 2.19.0+ requires >=3.9)"},{"message":"Authentication is a common source of errors. The client library uses Application Default Credentials (ADC) by default, but it must be correctly configured in your environment (e.g., via `gcloud auth application-default login` locally, or by attaching a service account to your compute resource in GCP). Incorrect permissions for the executing service account (e.g., lacking `roles/cloudscheduler.admin` or permissions to invoke the target) will lead to 401/403 errors.","severity":"gotcha"},{"fix":"Use `from google.cloud import scheduler_v1` for stable production code. Only use `scheduler_v1beta1` if you explicitly require a beta feature and understand the implications.","message":"Google Cloud client libraries often offer multiple API versions (e.g., `v1`, `v1beta1`). While `v1beta1` might contain newer features, it is a beta API and not guaranteed to be stable or backward compatible. Always prefer `v1` for production workloads to ensure stability and avoid unexpected breaking changes.","severity":"gotcha","affected_versions":"All versions where `v1beta1` exists alongside `v1`"},{"message":"Incorrectly configuring job targets (HTTP, Pub/Sub, App Engine) can lead to silent failures or unexpected behavior. Pay close attention to `uri`, `http_method`, `headers`, `schedule` (cron format), and `time_zone`. For HTTP targets, ensure the `Content-Type` header is explicitly set if your endpoint expects a specific type, as `application/octet-stream` is a common default.","severity":"gotcha"},{"message":"Cloud Scheduler jobs have a default timeout (e.g., 30 minutes for HTTP targets). If your scheduled task is long-running and exceeds this, Cloud Scheduler will report a failure even if the downstream service eventually succeeds. Also, retry configurations must be carefully tuned to avoid overwhelming the target or incurring excessive costs.","severity":"gotcha"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}