{"id":7254,"library":"gcloud-rest-taskqueue","title":"Google Cloud Task Queue Client (gcloud-aio)","description":"The `gcloud-rest-taskqueue` library provides an asynchronous Python client for interacting with Google Cloud Task Queue. It is part of the `gcloud-aio` monorepo, offering async functionality (via `aiohttp`) for various Google Cloud services. Currently at version 7.0.0, it follows a demand-driven release cadence as part of the larger `gcloud-aio` project.","status":"active","version":"7.0.0","language":"en","source_language":"en","source_url":"https://github.com/talkiq/gcloud-aio","tags":["Google Cloud","Task Queue","asynchronous","aiohttp","cloud tasks"],"install":[{"cmd":"pip install gcloud-rest-taskqueue","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core asynchronous HTTP client dependency.","package":"aiohttp","optional":false},{"reason":"Used for managing connection timeouts.","package":"async-timeout","optional":false},{"reason":"Provides asynchronous Google Cloud authentication utilities, used by the TaskQueue client.","package":"gcloud-aio-auth","optional":false}],"imports":[{"note":"For versions 7.0.0+, TaskQueueClient is directly exposed by the package's top-level __init__. Earlier versions might have required importing from a .client submodule.","wrong":"from gcloud.aio.taskqueue.client import TaskQueueClient","symbol":"TaskQueueClient","correct":"from gcloud.aio.taskqueue import TaskQueueClient"},{"note":"This helper function from `gcloud-aio-auth` is commonly used to set up an authenticated aiohttp.ClientSession.","symbol":"build_from_env","correct":"from gcloud.aio.auth import build_from_env"}],"quickstart":{"code":"import asyncio\nimport os\n\nfrom gcloud.aio.auth import build_from_env\nfrom gcloud.aio.taskqueue import TaskQueueClient\n\nasync def main():\n    async with build_from_env() as client_session:\n        # Replace with your actual project ID and desired location\n        project_id = os.environ.get(\"GCLOUD_PROJECT\", \"your-gcp-project-id\")\n        location = os.environ.get(\"GCLOUD_TASKQUEUE_LOCATION\", \"us-east1\") # e.g., 'us-central1'\n        queue_name = os.environ.get(\"GCLOUD_TASKQUEUE_NAME\", \"my-queue\") # e.g., 'my-queue'\n        \n        if not project_id or project_id == \"your-gcp-project-id\":\n            print(\"Please set GCLOUD_PROJECT environment variable or replace 'your-gcp-project-id'.\")\n            return\n\n        client = TaskQueueClient(\n            project=project_id,\n            location=location,\n            session=client_session\n        )\n\n        task_name = \"my-test-task-1\"\n        payload = {\"data\": \"hello world\", \"timestamp\": \"2023-01-01T12:00:00Z\"}\n\n        try:\n            await client.create_task(\n                project=project_id,\n                location=location,\n                queue_name=queue_name,\n                task_name=task_name,\n                payload=payload\n            )\n            print(f\"Task '{task_name}' created successfully in queue '{queue_name}' in project '{project_id}'.\")\n        except Exception as e:\n            print(f\"Failed to create task: {e}\")\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize the `TaskQueueClient` and create a task asynchronously. Ensure your `GCLOUD_PROJECT` environment variable is set and that Google Application Credentials are available for authentication."},"warnings":[{"fix":"Upgrade Python to 3.8+ or pin `gcloud-rest-taskqueue` to `<7.0.0`.","message":"Version 7.0.0 of `gcloud-rest-taskqueue` (and `gcloud-aio-taskqueue`) drops support for Python 3.7. Users on Python 3.7 should remain on version 6.x or upgrade their Python interpreter.","severity":"breaking","affected_versions":"7.0.0+"},{"fix":"Upgrade Python to 3.7+ or pin `gcloud-rest-taskqueue` to `<6.0.0`.","message":"Version 6.0.0 of `gcloud-rest-taskqueue` (and `gcloud-aio-taskqueue`) dropped support for Python 3.6. Users on Python 3.6 should remain on version 5.x or upgrade their Python interpreter.","severity":"breaking","affected_versions":"6.0.0+"},{"fix":"Ensure all client method calls are prefixed with `await` and the entry point uses `asyncio.run()`.","message":"This library is an asynchronous client. All API calls must be `await`ed within an `async def` function, which then needs to be executed using `asyncio.run()` (or similar event loop management). Direct synchronous calls will result in `RuntimeError` or `NameError`.","severity":"gotcha","affected_versions":"All"},{"fix":"Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account JSON key file, or ensure appropriate IAM roles are assigned to your GCP service.","message":"Authentication relies on Google Application Credentials. If not explicitly provided, the client will attempt to infer them from the environment (e.g., `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to a service account key file, or default credentials when running on GCP services).","severity":"gotcha","affected_versions":"All"},{"fix":"Choose the client that best fits your application's asynchronous requirements and ensure you consult the correct documentation for the chosen library.","message":"This `gcloud-rest-taskqueue` library (part of `gcloud-aio`) is an *asynchronous* client using `aiohttp`. It is distinct from Google's official `google-cloud-tasks` client library, which uses gRPC and offers both synchronous and wrapped asynchronous APIs. The API signatures and underlying implementations are different.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Wrap your asynchronous code in an `async def` function and run it using `asyncio.run(your_async_function())`.","cause":"Attempting to use the `await` keyword outside of an `async` function.","error":"NameError: name 'await' is not defined"},{"fix":"Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the file path of your service account JSON key, or ensure your application is running in an environment (e.g., GCE, Cloud Run) where default credentials are automatically provided.","cause":"The client could not find valid Google Application Credentials to authenticate with Google Cloud. This usually means the `GOOGLE_APPLICATION_CREDENTIALS` environment variable is not set, or the specified file is invalid/inaccessible.","error":"google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials."},{"fix":"Verify your internet connection, check local and network firewall rules (port 443), ensure DNS resolution is working, and confirm the Google Cloud Task Queue API is enabled for your project.","cause":"Network connectivity issue preventing the client from reaching the Google Cloud Task Queue API endpoint. This can be due to DNS resolution problems, firewall rules, or an unstable internet connection.","error":"aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host taskqueue.googleapis.com:443 ssl:default [Name or service not known]"},{"fix":"Ensure you are using `gcloud-rest-taskqueue` version 7.0.0+ and importing with `from gcloud.aio.taskqueue import TaskQueueClient`. If on an older version, consult its specific documentation for the correct import path.","cause":"You are likely using an older version of the `gcloud-aio-taskqueue` library, or a very old version where the class might have been named differently or imported from a submodule (e.g., `gcloud.aio.taskqueue.client`).","error":"AttributeError: module 'gcloud.aio.taskqueue' has no attribute 'TaskQueueClient'"}]}