[Tutorial][Trello][API] How to use py-trello.

It turns out that using py-trello was exactly like how you think you would.

import trello
from trello import TrelloClient

client = TrelloClient(api_key=API_KEY,token=API_TOKEN)

boards = client.list_boards()

The thing I didn’t know was just explicitly (api_key=API_KEY) putting in the information I had. The example on the readme seemed to say you needed four pieces of information, but the key and token worked just fine.

Once you have the client variable, then you can get all the boards and it’s pretty easy from there.

There’s a list of different things you can do here.

What if you wanted to get a list of open boards. The variable boards returns all boards, including the closed ones.

def get_open_boards(boards):
    open_boards = []
    for board in boards:
        if board.closed == False:
            open_boards.append(board)
    return open_boards

Just pass in boards and there you go.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s