{"id":1335,"library":"asana","title":"Asana Python Client Library","description":"The official Python client library for interacting with the Asana API. It provides a simple interface to access Asana resources like tasks, projects, users, and workspaces. The current version is 5.2.4, and the library receives frequent updates, typically focusing on adding support for new API endpoints.","status":"active","version":"5.2.4","language":"en","source_language":"en","source_url":"https://github.com/asana/python-asana","tags":["API client","SaaS","project management","productivity"],"install":[{"cmd":"pip install asana","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"HTTP client for making API requests.","package":"requests"},{"reason":"Required for OAuth 2.0 authentication flow.","package":"oauthlib","optional":true},{"reason":"Provides OAuth 2.0 support for requests.","package":"requests_oauthlib","optional":true}],"imports":[{"note":"The Client constructor is commonly accessed via class methods like `access_token` or `oauth`.","wrong":"from asana import Client # While technically possible, the recommended pattern is via asana.Client.access_token or asana.Client.oauth","symbol":"Client","correct":"import asana\nclient = asana.Client.access_token('YOUR_PAT')"}],"quickstart":{"code":"import asana\nimport os\n\n# Get your Personal Access Token from environment variable for security\npersonal_access_token = os.environ.get('ASANA_ACCESS_TOKEN', 'YOUR_ASANA_PAT')\n\nif not personal_access_token or personal_access_token == 'YOUR_ASANA_PAT':\n    print(\"Please set the ASANA_ACCESS_TOKEN environment variable or replace 'YOUR_ASANA_PAT' with your token.\")\nelse:\n    try:\n        # Construct an Asana client\n        client = asana.Client.access_token(personal_access_token)\n        \n        # Get information about the current user ('me')\n        me = client.users.get_user('me')\n        print(f\"Connected as: {me['name']} (ID: {me['gid']})\")\n        \n        # List workspaces accessible by the user\n        workspaces = client.workspaces.get_workspaces(iterator_type=None) # iterator_type=None to get all results directly\n        print(\"Workspaces:\")\n        for ws in workspaces:\n            print(f\"- {ws['name']} (ID: {ws['gid']})\")\n            \n    except asana.error.NoAuthorizationError:\n        print(\"Error: Invalid or expired Asana Personal Access Token.\")\n    except Exception as e:\n        print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the Asana client using a Personal Access Token (PAT) and fetch the current user's details and a list of accessible workspaces. It handles token retrieval from environment variables for security and includes basic error handling."},"warnings":[{"fix":"Update client instantiation to `asana.Client.access_token('YOUR_PAT')` or `asana.Client.oauth(...)`. Replace old resource methods (`projects.find_all`) with their v4+ equivalents (`projects.get_projects`). Consult the official v4 migration guide if available, or the current documentation.","message":"Major API changes in v4.0.0 altered client instantiation and resource method names. Older versions (pre-v4) used different patterns like `client.Client(api_key='...')` and resource methods such as `find_all` or `find_by_id`.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"To iterate through results: `for item in client.tasks.get_tasks(...)`. To get all results as a list (for smaller collections, use with caution for large ones): `list(client.tasks.get_tasks(...))` or pass `iterator_type=None` to the method, e.g., `client.tasks.get_tasks(workspace_gid, iterator_type=None)`.","message":"Many collection-fetching methods (e.g., `get_tasks`, `get_projects`) return an `asana.Collection` object. This object is an iterator and does not immediately contain all results. To retrieve all items, you must iterate over it or explicitly request all results.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"When calling any `get_` method for resources, pass a list of desired fields to `opt_fields`. Example: `task = client.tasks.get_task(task_gid, opt_fields=['name', 'notes', 'assignee.name'])`. This also applies to collection fetching methods.","message":"Asana API responses can be verbose. To optimize performance and reduce data transfer, always use the `opt_fields` parameter to specify only the fields you need in the response.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}