Python

🚧

Important

Version 5.X.X is the newest release of our Python client library and currently in public beta. This means that while it has the latest Asana features, we're still putting on the final touches to ensure it's as stable and reliable as possible.

🛠️ Looking Ahead

This version will receive updates going forward, and it’s on track to reach full stability soon. Your input is invaluable in this process! If you spot any issues, have suggestions, or need help, don’t hesitate to reach out. You can open a GitHub issue or submit your feedback directly to us.

📖 Get Started with Examples and Resources

For now, if you’re in search of a version that has stood the test of time and is proven to be stable, we recommend using version v3.2.2. You can easily install it using: pip install asana==3.2.2 and following v3 samples. You can access the sample code for v3.2.2 under the drop down from the API reference for Python (EX: Get a user -> "Default" drop down choose "python-sdk-v3")

Installation

pip install asana
pip install asana==4.0.11

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 /gen folder of the client library.