{"id":4274,"library":"tasq-client-python","title":"Tasq Client Python","description":"tasq-client-python is the official Python client library for the Tasq HTTP-based task queue server. The Tasq server (https://github.com/unixpickle/tasq) is a simple, lightweight system where tasks are pushed to a queue via HTTP endpoints, popped by workers, and then marked as complete. This client simplifies interaction with a running Tasq server, allowing Python applications to easily enqueue and process tasks. The library is currently at version 0.1.24 and has an irregular but active release cadence, tied to the development of the main Tasq server project.","status":"active","version":"0.1.24","language":"en","source_language":"en","source_url":"https://github.com/unixpickle/tasq/tree/master/tasq-client-python","tags":["queue","task management","http client","worker"],"install":[{"cmd":"pip install tasq-client-python","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"TasqClient","correct":"from tasqclient import TasqClient"},{"symbol":"TasqTask","correct":"from tasqclient import TasqTask"}],"quickstart":{"code":"import asyncio\nfrom tasqclient import TasqClient\nimport os\n\nTASQ_SERVER_URL = os.environ.get('TASQ_SERVER_URL', 'http://localhost:8080')\n\nasync def main():\n    client = TasqClient(base_url=TASQ_SERVER_URL)\n    print(f\"Connected to Tasq server at {TASQ_SERVER_URL}\")\n\n    # Clear any existing tasks for a clean start\n    await client.clear()\n    print(\"Cleared existing tasks.\")\n\n    # Push a task\n    task_content = \"my-first-task-content\"\n    pushed_task = await client.push(task_content)\n    print(f\"Pushed task with ID: {pushed_task.id}, Content: {pushed_task.contents}\")\n\n    # Pop a task\n    popped_task = await client.pop(timeout=0.1) # Short timeout for example\n    if popped_task:\n        print(f\"Popped task with ID: {popped_task.id}, Content: {popped_task.contents}\")\n\n        # Complete the task\n        await client.complete(popped_task.id)\n        print(f\"Completed task with ID: {popped_task.id}\")\n    else:\n        print(\"No task available to pop.\")\n    \n    # Get current counts\n    counts = await client.get_counts()\n    print(f\"Current task counts: {counts}\")\n\nif __name__ == \"__main__\":\n    # Note: A Tasq server should be running at TASQ_SERVER_URL for this to work.\n    # You can run the server using `tasq -save-path state.json` in a separate terminal.\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates how to initialize the TasqClient, push a task to the queue, pop it, and mark it as complete. It also shows how to clear the queue and get current task counts. Ensure a Tasq server is running and accessible at the specified URL (defaults to http://localhost:8080) for the example to function correctly."},"warnings":[{"fix":"Implement idempotent workers that can safely re-process tasks. For critical tasks, consider more robust queueing systems with stronger guarantees, or frequently save the Tasq server state if using file persistence.","message":"The Tasq server's persistence mechanism (when using file-based saving) has limitations. Tasks pushed between the last save and a server restart will be lost. Tasks completed during this interval may reappear in the queue upon restart, requiring workers to be idempotent and handle already-completed tasks.","severity":"gotcha","affected_versions":"All versions of Tasq server utilizing file persistence"},{"fix":"Consult the `unixpickle/tasq` GitHub repository's README (https://github.com/unixpickle/tasq) for the most up-to-date and complete documentation.","message":"The PyPI project page for `tasq-client-python` lacks a detailed description or direct link to documentation. Users must refer to the main `unixpickle/tasq` GitHub repository for comprehensive usage information, server setup, and protocol details.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Before using `tasq-client-python`, ensure the `tasq` server is installed and running, accessible via HTTP at the `base_url` provided to the `TasqClient` constructor. Refer to the Tasq server's GitHub for installation and running instructions.","message":"The `tasq-client-python` library is a client for the `tasq` server (https://github.com/unixpickle/tasq). This means you need a running `tasq` server instance for the client to function. Simply installing the Python client is not enough to have a functional task queue.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}