Saturday, January 20, 2018

Using Python to access your Trello Boards



Here is a really basic tutorial on using Python to set up and start accessing your Trello boards.

This works with Python 2.7!

First, let's start with installing the python package used to easily access the Trello API:

pip install py-trello

Next, You will need an APPKEY and a Token.
To get your App Key, go to https://trello.com/app-key  and find your App Key. Copy that.
Next, you will need your Token. Click the "Token" and authorize until you receive the following message:

There is your token!

Next, get your Board ID! When you are in Trello, open your Board. The URL will be something like "https://trello.com/b/{HERE IS YOUR BOARD ID}/{THE NAME OF YOUR BOARD}"

Add those pieces of information to a Python file called "myconfig.py"
# myconfig.py:

APPKEY = 'PASTE YOUR API KEY HERE'
TOKEN = 'PASTE YOUR TOKEN HERE'
BOARD_ID = 'PASTE YOUR BOARD ID HERE'


In a different file (e.g., test.py), enter the following code:

from myconfig import *
from trello import TrelloClient


client = TrelloClient(
 api_key=APPKEY,
 api_secret=TOKEN
)

my_board = client.get_board(BOARD_ID)
print my_board.name


Why are we using myconfig.py? This allows us to share our programs without sharing our API Key, Token, and Board Id.

Now when you run this simple example, you will connect to Trello and the program will print out the name of your board. Pretty simple, but once you get here and have the connection working, then the rest will come much easier.

No comments:

Post a Comment