Installation

pip install asana
pip install asana==3.2.2

Hello world

In this brief tutorial, we'll build a GET request to /users/me using the Python client library.

To get started, be sure that you have installed the library (pip install asana). You may also follow the detailed installation instructions on the GitHub page for the Python client library. Then, once the library is installed:

  1. Copy the example code below:
# Import the library
import asana
from asana.rest import ApiException

# Configure personal access token
configuration = asana.Configuration()
configuration.access_token = '0/123456789....'
api_client = asana.ApiClient(configuration)

# Construct resource API Instance
users_api_instance = asana.UsersApi(api_client)
user_gid = "me"
opts = {}

try:
    # Get your user info
    me = users_api_instance.get_user(user_gid, opts)

    # Print out your information
    print("Hello world! " + "My name is " + me["name"] + "!")
except ApiException as e:
    print("Exception when calling UsersApi->get_user: %s\n" % e)
import asana

# Note: Replace this value with your own personal access token
personal_access_token = '0/123456789....'

# Construct an Asana client
client = asana.Client.access_token(personal_access_token)

# Set things up to send the name of this script to us to show that you succeeded! This is optional.
client.options['client_name'] = "hello_world_python"

# Get your user info
me = client.users.get_user("me")

# Print out your information
print("Hello world! " + "My name is " + me['name'] + "!")
  1. Open a text editor and save this code in a file (i.e., a descriptive file name such as hello_world.py).

  2. Run this script in your console by passing it as an argument to the Python interpreter: python hello_world.py. You must execute this command in the same directory as the file.

  3. You should see the response outputted to the console!

As an aside, for clarity python-asana will also work with Python 3.x (with minor changes to the above example to make it compatible.)

You can see a variant of this script, and other useful Asana API scripts, in our open-source devrel-examples.


GitHub

You can access the library's source code on GitHub.

All of the built-in functions can be found in the "Documentation for API Endpoints" section of the client library README.md.