Exporting your Trello-Boards with Python

Uwe Ziegenhagen
3 min readApr 19, 2020

After having tried every possible way of capturing my todos (Palm Pilot, Sony Clié, Psion 3, Psion 5, Trello, Filofax, Time/System, Emacs orgmode, taskwarrior, just to name a few [!]) I am currently experimenting with bullet journals. Not with the fancy-style lists you can see on Pinterest or Instagram, but with the rational list of todo items that is carried from day to day on paper.

For my “someday log” I am not yet so far that I would like to have it handwritten, as this is not going to change regularly a printed list would be nice. I have also been a long-term user of the free Trello version so my idea is to mix both worlds: keep the someday with future projects in digital form and export them to paper if necessary.

When I checked Trello for ways to export my list I only found the JSON export to be freely available, the CSV export is only available for paying customers. I didn’t want to mingle with JSON so I decided to look for other options.

The solution came in form of the py-trello Python package that I was able to install easily with Python’s package manager:

pip install py-trello

This package wraps the Trello API (the interface that you can use to interact with Trello programmatically) in Python code, each object on the Trello side gets a representation in Python. As I love working with Python, I consider it a really intuitive and beginner-friendly language, this is a real advantage for me.

With the package installed it was time to get access to the boards. What I needed was a) the API-key, a 32 characters long string and and an access token, which is even longer. I got both on https://trello.com/app-key.

Now it was time for the coding. The homepage of the py-trello module contained some code samples which I basically only had to take and adapt.

Load the package and create a client instance with the API key and token.

from trello import TrelloClient

client = TrelloClient(
api_key='<secret_api_key>',
token='<secret_token>'
)

Define a function which lists all the boards with their ID. We will use this ID to access a specific board in the next step.

def list_all_boards(client):
"""
get list of all boards to determine the ID
for further functions
"""
all_boards = client.list_boards()
for counter, board in enumerate(all_boards):
print(counter, board.name)

The next function allows us to access a specific board and prints all its lists with all cards, but only if they have not been archived.

def print_cards_from_board(board_id, client):
"""
Access board with ID board_id in the client instance
and print all non-archived lists with their non-archived
cards
"""
all_boards = client.list_boards()
my_board = all_boards[board_id]
all_lists_on_board = my_board.list_lists()

for list in all_lists_on_board:
if not list.closed:
for card in list.list_cards():
if not card.closed:
print(list.name, ':' , card.name)

print_cards_from_board(15, client) # ID 15 is my someday board

The output this function generates in the form

Listname : Cardname

is still very basic, but now we have all the code to generate arbitrary formats. No matter if RTF for office programs, LaTeX code for the awesome typesetting system, Markdown or HTML, it’s all just a matter of adapting or extending the last function.

I have placed the code in a Github repository, you will find updates to the code there as well: https://github.com/UweZiegenhagen/python-trello-output/

--

--

Uwe Ziegenhagen

From Cologne, Germany, working in the financial industry as a specialist for data-related topics. Hobbies include LaTeX typesetting, electronics and programming