{"id":6653,"library":"gcloud-aio-taskqueue","title":"Google Cloud Task Queue Client (Asyncio)","description":"An asynchronous Python client for interacting with Google Cloud Task Queue. This library is part of the `gcloud-aio` ecosystem, providing idiomatic `asyncio` support for various Google Cloud services. As an independent sub-package, its releases are decoupled from other `gcloud-aio` components, and it's currently at version 7.0.0.","status":"active","version":"7.0.0","language":"en","source_language":"en","source_url":"https://github.com/talkiq/gcloud-aio","tags":["google-cloud","task-queue","asyncio","gcp","aiohttp","cloud-tasks"],"install":[{"cmd":"pip install gcloud-aio-taskqueue","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core HTTP client for asynchronous requests.","package":"aiohttp"},{"reason":"Provides shared authentication and session management utilities for gcloud-aio libraries.","package":"gcloud-aio-core"},{"reason":"Required for gRPC communication with Google Cloud APIs.","package":"grpcio"},{"reason":"Required for gRPC communication with Google Cloud APIs.","package":"grpcio-tools"},{"reason":"Used for serializing and deserializing data for gRPC.","package":"protobuf"}],"imports":[{"note":"The main client class was renamed from `Client` to `TaskQueueClient` in v7.0.0 to improve clarity and avoid naming conflicts.","wrong":"from gcloud_aio_taskqueue import Client","symbol":"TaskQueueClient","correct":"from gcloud_aio_taskqueue import TaskQueueClient"},{"note":"The core session management class, part of `gcloud-aio-core`.","symbol":"Session","correct":"from gcloud_aio_core.session import Session"},{"note":"The recommended way to build credentials; `Authenticator` is an older, less direct pattern.","wrong":"from gcloud_aio_core.auth import Authenticator","symbol":"build_credentials","correct":"from gcloud_aio_core.auth import build_credentials"},{"note":"Required enum for specifying HTTP methods when adding tasks since v6.0.0.","symbol":"HttpMethod","correct":"from gcloud_aio_taskqueue.types import HttpMethod"}],"quickstart":{"code":"import asyncio\nimport os\nfrom gcloud_aio_taskqueue import TaskQueueClient\nfrom gcloud_aio_taskqueue.types import HttpMethod\nfrom gcloud_aio_core.session import Session\nfrom gcloud_aio_core.auth import build_credentials\n\nasync def main():\n    project_id = os.environ.get(\"GCP_PROJECT_ID\", \"your-project-id\")\n    queue_name = os.environ.get(\"GCP_TASK_QUEUE_NAME\", \"your-queue-name\")\n    \n    # Authenticate using GOOGLE_APPLICATION_CREDENTIALS env var or a service account path\n    # Example: GOOGLE_APPLICATION_CREDENTIALS=/path/to/key.json\n    credentials = build_credentials()\n\n    async with Session(credentials) as session:\n        client = TaskQueueClient(\n            project=project_id,\n            queue=queue_name,\n            session=session,\n        )\n\n        try:\n            # Add a task with required parameters (changes from v6.0.0 onwards)\n            task = await client.add_task(\n                url=\"https://example.com/mytaskendpoint\",\n                body=b\"Hello World!\",\n                payload_type=\"APPLICATION_OCTET_STREAM\",\n                method=HttpMethod.POST,\n                headers={\n                    \"Content-Type\": \"application/octet-stream\",\n                    \"X-Cloud-Task-ETA\": \"2025-01-01T00:00:00Z\" # Example custom header\n                }\n            )\n            print(f\"Task added: {task.name} (ID: {task.id})\")\n\n            # Example: Get a task\n            retrieved_task = await client.get_task(task.name)\n            print(f\"Retrieved task: {retrieved_task.name}\")\n\n            # Example: Delete a task\n            await client.delete_task(task.name)\n            print(f\"Task {task.name} deleted.\")\n\n        except Exception as e:\n            print(f\"An error occurred: {e}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(main())","lang":"python","description":"This quickstart demonstrates how to initialize the `TaskQueueClient`, authenticate using environment variables or service account paths, and perform common operations like adding, retrieving, and deleting tasks. It highlights the use of `gcloud_aio_core.session.Session` for proper async context management and necessary parameters for `add_task` after recent breaking changes."},"warnings":[{"fix":"Update your code to expect and handle the returned `Task` object, accessing its `name` or `id` attributes directly. Previously, you would not get a direct return value from `add_task`.","message":"The `add_task` method now returns a `Task` object instead of `None`.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Replace `payload=my_data` with `body=my_data`. Also, `payload_type` is now a mandatory parameter specifying the content type of the body.","message":"The `payload` parameter for `add_task` was removed and replaced with `body`.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Import `HttpMethod` from `gcloud_aio_taskqueue.types` and use it (e.g., `method=HttpMethod.POST`) instead of string literals (e.g., `method='POST'`).","message":"The `method` parameter for `add_task` now requires an `HttpMethod` enum member instead of a string.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Update your imports from `from gcloud_aio_taskqueue import Client` to `from gcloud_aio_taskqueue import TaskQueueClient`.","message":"The `Client` class was renamed to `TaskQueueClient` for better clarity and consistency.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Ensure your client instantiation and usage is wrapped in an `async with Session(...) as session:` block to properly handle resource cleanup and avoid connection leaks.","message":"Always manage `gcloud_aio_core.session.Session` or `aiohttp.ClientSession` as an async context manager (`async with`).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}