Asana Python Client Library

5.2.4 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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.

import asana
import os

# Get your Personal Access Token from environment variable for security
personal_access_token = os.environ.get('ASANA_ACCESS_TOKEN', 'YOUR_ASANA_PAT')

if not personal_access_token or personal_access_token == 'YOUR_ASANA_PAT':
    print("Please set the ASANA_ACCESS_TOKEN environment variable or replace 'YOUR_ASANA_PAT' with your token.")
else:
    try:
        # Construct an Asana client
        client = asana.Client.access_token(personal_access_token)
        
        # Get information about the current user ('me')
        me = client.users.get_user('me')
        print(f"Connected as: {me['name']} (ID: {me['gid']})")
        
        # List workspaces accessible by the user
        workspaces = client.workspaces.get_workspaces(iterator_type=None) # iterator_type=None to get all results directly
        print("Workspaces:")
        for ws in workspaces:
            print(f"- {ws['name']} (ID: {ws['gid']})")
            
    except asana.error.NoAuthorizationError:
        print("Error: Invalid or expired Asana Personal Access Token.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →