Python API wrapper around Trello's API

Overview

A wrapper around the Trello API written in Python. Each Trello object is represented by a corresponding Python object. The attributes of these objects are cached, but the child objects are not. This can possibly be improved when the API allows for notification subscriptions; this would allow caching (assuming a connection was available to invalidate the cache as appropriate).

I've created a Trello Board for feature requests, discussion and some development tracking.

Install

pip install py-trello

Usage

from trello import TrelloClient

client = TrelloClient(
    api_key='your-key',
    api_secret='your-secret',
    token='your-oauth-token-key',
    token_secret='your-oauth-token-secret'
)

Where token and token_secret come from the 3-legged OAuth process and api_key and api_secret are your Trello API credentials that are (generated here).

To use without 3-legged OAuth, use only api_key and api_secret on client.

Working with boards

all_boards = client.list_boards()
last_board = all_boards[-1]
print(last_board.name)

working with board lists and cards

all_boards = client.list_boards()
last_board = all_boards[-1]
last_board.list_lists()
my_list = last_board.get_list(list_id)

for card in my_list.list_cards():
    print(card.name)

Getting your Trello OAuth Token

Make sure the following environment variables are set:

  • TRELLO_API_KEY
  • TRELLO_API_SECRET

These are obtained from the link mentioned above.

TRELLO_EXPIRATION is optional. Set it to a string such as 'never' or '1day'. Trello's default OAuth Token expiration is 30 days.

Default permissions are read/write.

More info on setting the expiration here: https://trello.com/docs/gettingstarted/#getting-a-token-from-a-user

Run

python -m trello oauth

Required Python modules

Found in requirements.txt

Tests

To run the tests, run python -m unittest discover. Four environment variables must be set:

  • TRELLO_API_KEY: your Trello API key
  • TRELLO_TOKEN: your Trello OAuth token
  • TRELLO_TEST_BOARD_COUNT: the number of boards in your Trello account
  • TRELLO_TEST_BOARD_NAME: name of the board to test card manipulation on. Must be unique, or the first match will be used
  • TRELLO_TEST_STAR_COUNT: the number of stars on your test Trello board

WARNING: The tests will delete all cards on the board called TRELLO_TEST_BOARD_NAME!

To run tests across various Python versions, tox is supported. Install it and simply run tox from the py-trello directory.

Comments
  • Added two methods for checkitems

    Added two methods for checkitems

    The methods below set due dates and add members. The Trello API does not list either actions officially but does support it it in the UI and both worked in my production environment. set_checklist_item_due() set_checklist_item_member()

    opened by rdorrigan 11
  • KeyError: 'customFieldItems'

    KeyError: 'customFieldItems'

    Traceback (most recent call last):
      File "scripts/trello_requirements.py", line 242, in <module>
        main()
      File "scripts/trello_requirements.py", line 238, in main
        args.dry_run, args.lookup_method, args.approver)
      File "scripts/trello_requirements.py", line 144, in get_trello_board_content
        tcards = board.get_cards()
      File "/var/lib/jenkins/workspace/trello-to-polarion-igulina/Polarion_Scripts/.venv/lib/python2.7/site-packages/trello/board.py", line 302, in get_cards
        return list([Card.from_json(self, json) for json in json_obj])
      File "/var/lib/jenkins/workspace/trello-to-polarion-igulina/Polarion_Scripts/.venv/lib/python2.7/site-packages/trello/card.py", line 157, in from_json
        card.customFields = CustomField.from_json_list(card, json_obj['customFieldItems'])
    KeyError: 'customFieldItems'
    
    opened by alexxa 11
  • NameError: name 'unicode' is not defined

    NameError: name 'unicode' is not defined

    Error:

    File "/usr/local/lib/python3.4/dist-packages/trello/compat.py", line 13, in force_str if PY2 and isinstance(s, unicode): # noqa NameError: name 'unicode' is not defined

    when calling list_boards() on a TrelloClient instance.

    Works fine in version 0.5.0 but breaks in 0.6.0.

    Python version: 3.4.3 sys.version_info returns:

    sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)

    opened by NiFNi 7
  • Maintain PyPi py-trello up-to-date

    Maintain PyPi py-trello up-to-date

    When we talk about Python, one of the first things that comes to mind is PyPi, the great packages repository. This Trello wrapper is amazing but it's always outdated on PyPi vs here on Github. It would be amazing if the contributors could maintain both platforms up-to-date and aligned.

    opened by juanchristian 6
  • No Way to Update Board Name

    No Way to Update Board Name

    Forgive me if I am missing something but, from what I can tell, there is no way to update a board name. I can,

    get the board with: my_board = client.get_board(board_id='someBoardId')

    update the name with: my_board.name = "New Board Name"

    But the save function is doing a POST rather than a PUT so the new name is not saved. my_board.save()

    Shouldn't this functionality exist? https://developers.trello.com/advanced-reference/board#put-1-boards-board-id-name

    Please let me know if I am just missing something.

    Thanks!

    Brandon Culpepper

    opened by bculpepper 6
  • Unicode handling

    Unicode handling

    In various places py-trello .encode('utf-8') some strings returned by the API.

    What's the rationale behind this? Trello data is returned in JSON, with string keys and attributes in unicode strings (u'foo' in Python 2, 'foo' in Python 3).

    Keeping unicode would make sense: in Python 2 you can compare bytestrings to unicode strings implicitly (u'foo' == 'foo'), but in Python 3 it'd make more sense to compare e.g. board.name to unicode strings instead of bytestrings. In Python 3 our code needs to re-decode data for comparison or string formatting. We have things like:

    if board.name == b'Board name'

    or:

    message = '{}: {}'.format(board.name.decode(), card.name.decode())

    My suggested fix would be to remove all occurrences of .encode('utf-8') here, to have a proper unicode sandwich behavior. Any objections? I'm happy to submit a PR.

    opened by brutasse 6
  • Fetch comments from copied cards

    Fetch comments from copied cards

    I stumbled upon this while writing a backup script. For a copied card, everything that I wanted was there, except for the comments. It seems the action is different in that situation.

    Some test output, prior this change:

    ### Sample Card
    
    2019-05-07T16:00:00.000Z
    
    Sample description
    
    1 checklists
    1 comments
    1 attachments
    
    ### Copied Card
    
    2019-05-07T16:00:00.000Z
    
    Sample description
    
    1 checklists
    0 comments
    1 attachments
    

    After, the 0 comments becomes 1 comments.

    opened by bhrutledge 5
  • Add function for accessing new/existing custom fields of a card by name

    Add function for accessing new/existing custom fields of a card by name

    As enhancement for the new custom field functionality I added a new function for getting a proper custom field instance for a specific card - only by specifying the custom field name.

    Examples: cf = card_obj.get_custom_field_by_name('MyText') cf.value = u'This is my test text' cf = card_obj.get_custom_field_by_name('MyBool') cf.value = True

    opened by JuergenBS 5
  • AttributeError: 'Http' object has no attribute 'fetch_json' when calling list_cards()

    AttributeError: 'Http' object has no attribute 'fetch_json' when calling list_cards()

    When I run an example list test40_add_card() in test_trello.py, I have no trouble calling add_card() on a list object, however, if I get a card in a different way, then it looks like the client attribute isn't initialized correctly. My usage is a bit convoluted, namely because I don't see a way to fetch a card by its ID or its name, but: b = trello.get_board('myboard') for card in b.get_cards(myfilter): if card == desired_card: l = trello.get_list(card.idList) l.add_card(cardname, 'delete me')

    gives me the AttributeError. The documentation is a little sparse but am I expected to initialize objects in a certain order or ... ?

    Ultimately I'm trying to implement a List.copy_card() method to create a new card from a template in a given list.

    opened by skmcclure 5
  • Inconsistent `card.label` typing

    Inconsistent `card.label` typing

    If a card has labels a list of <Label> is returned, but if it has none, None is returned. Why? It would seem preferable to me to return an empty list, since this

    • doesn't break things that depend on a list (ie iterating a card's labels)
    • better represents the actual labels on a card (an empty set of lables, which is different from nothing)
    opened by gastrodon 4
  • Trello __init__.py import urllib --> urllib.parse

    Trello __init__.py import urllib --> urllib.parse

    Hi, it seems Trello package cannot be imported when using Python 3.5.

    urllib package has been updated, now 'quote_plus' is in urllib.parse

    import trello Traceback (most recent call last): File "", line 1, in File "~\Anaconda3\envs\trello\lib\site-packages\trello_init_.py", line 1, in from urllib import quote_plus ImportError: cannot import name 'quote_plus'

    This init.py file should be updated; line 1 changed to:

    from urllib.parse import quote_plus

    opened by JoshZastrow 4
  • TypeError when accessing card checklists.

    TypeError when accessing card checklists.

    It seems that the Trello payload has changed when accessing cards data. The status of checklist items is not factorized in a checkItemStates section anymore but directly attached to them as a "state" attribute.

    Attempting to access a card's checklist raises the following stack trace:

    File "C:\virtualenvs\py-trello\lib\site-packages\trello\card.py", line 83, in checklists
        self._checklists = self.fetch_checklists()
      File "C:\virtualenvs\py-trello\lib\site-packages\trello\card.py", line 259, in fetch_checklists
        checklists.append(Checklist(self.client, self.checked, cl,
      File "C:\virtualenvs\py-trello\lib\site-packages\trello\checklist.py", line 22, in __init__
        for cis in checked:
    TypeError: 'NoneType' object is not iterable
    
    opened by chaami 1
  • Add support for getting a cards `cover` property

    Add support for getting a cards `cover` property

    The Trello API offers a cover property for cards (see docs), but it is not being loaded into the Card object here.

    It should be simple to at least "get" the property.

    Workaround I'm using for now (might be useful to someone else):

    def get_cover(card: 'Card') -> dict:
        """Gets the card's cover."""
        return card.client.fetch_json(f'/cards/{card.id}/cover')
    
    opened by augusto-herrmann 0
  • Get Start Date for Card?

    Get Start Date for Card?

    I'm aware that there is a way to get the due date of a card from card.due_date, but is there any way to get the start date of a card? Or any plans for implementing this?

    opened by richung99 1
  • Add a new method for downloading attachments

    Add a new method for downloading attachments

    The Trello API has changed the way they control access to attachments, e.g. a card image. Previously, you could just do an unauthenticated GET to the attachment URL and be done with it. Now, you have to get a token that is valid for 1 hour.

    This Python package should implement some functionality to help download these attachments more easily. Like maybe attachment.get_authenticated_download_url() using the credentials already present in the TrelloClient object.

    Please see this announcement and this thread.

    opened by augusto-herrmann 0
Owner
Richard Kolkovich
Richard Kolkovich
An API wrapper around Discord API.

NeoCord This project is work in progress not for production use. An asynchronous API wrapper around Discord API written in Python. Features Modern API

Izhar Ahmad 14 Jan 3, 2022
An API wrapper around the pythonanywhere's API.

pyaww An API wrapper around the pythonanywhere's API. The name stands for pythonanywherewrapper. 100% API coverage Most of the codebase is documented

null 7 Dec 11, 2022
A Python wrapper around the OpenWeatherMap web API

PyOWM A Python wrapper around OpenWeatherMap web APIs What is it? PyOWM is a client Python wrapper library for OpenWeatherMap (OWM) web APIs. It allow

Claudio Sparpaglione 740 Dec 18, 2022
A Python wrapper around the Soundcloud API

soundcloud-python A friendly wrapper around the Soundcloud API. Installation To install soundcloud-python, simply: pip install soundcloud Or if you'r

SoundCloud 83 Dec 12, 2022
A Python wrapper around the Twitter API.

Python Twitter A Python wrapper around the Twitter API. By the Python-Twitter Developers Introduction This library provides a pure Python interface fo

Mike Taylor 3.4k Jan 1, 2023
A Python wrapper around the Twitter API.

Python Twitter A Python wrapper around the Twitter API. By the Python-Twitter Developers Introduction This library provides a pure Python interface fo

Mike Taylor 3.4k Jan 1, 2023
An asyncio Python wrapper around the Discord API, forked off of Rapptz's Discord.py.

Novus A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. A full fork of Rapptz's Discord.py library, with

Voxel Fox 60 Jan 3, 2023
An async-ready Python wrapper around FerrisChat's API.

FerrisWheel An async-ready Python wrapper around FerrisChat's API. Installation Instructions Linux: $ python3.9 -m pip install -U ferriswheel Python 3

FerrisChat 8 Feb 8, 2022
A Python wrapper around the Pushbullet API to send different types of push notifications to your phone or/and computer.

pushbullet-python A Python wrapper around the Pushbullet API to send different types of push notifications to your phone or/and computer. Installation

Janu Lingeswaran 1 Jan 14, 2022
A light wrapper around FedEx's SOAP API.

Python FedEx SOAP API Module Author: Greg Taylor, Radek Wojcik Maintainer: Python FedEx Developers License: BSD Status: Stable What is it? A light wra

null 155 Dec 16, 2022
Wrapper around the Mega API

python-mega Overview Wrapper around the Mega API. Based on the work of Julien Marchand. Installation Install using pip, including any optional package

Juan Riaza 104 Nov 26, 2022
Wrapper around the latest Tuenti API

python-tuenti Overview Wrapper around the latest Tuenti API. Installation Install using pip, including any optional packages you want... $ pip install

Juan Riaza 10 Mar 7, 2022
Wrapper around the UPS API for creating shipping labels and fetching a package's tracking status.

ClassicUPS: A Useful UPS Library ClassicUPS is an Apache2 Licensed wrapper around the UPS API for creating shipping labels and fetching a package's tr

Jay Goel 55 Dec 12, 2022
RichWatch is wrapper around AWS Cloud Watch to display beautiful logs with help of Python library Rich.

RichWatch is TUI (Textual User Interface) for AWS Cloud Watch. It formats and pretty prints Cloud Watch's logs so they are much more readable. Because

null 21 Jul 25, 2022
🚀 An asynchronous python API wrapper meant to replace discord.py - Snappy discord api wrapper written with aiohttp & websockets

Pincer An asynchronous python API wrapper meant to replace discord.py ❗ The package is currently within the planning phase ?? Links |Join the discord

Pincer 125 Dec 26, 2022
Aws-lambda-requests-wrapper - Request/Response wrapper for AWS Lambda with API Gateway

AWS Lambda Requests Wrapper Request/Response wrapper for AWS Lambda with API Gat

null 1 May 20, 2022
Discord-Wrapper - Discord Websocket Wrapper in python

This does not currently work and is in development Discord Websocket Wrapper in

null 3 Oct 25, 2022
Playing around with the slack api for learning purposes

SlackBotTest Playing around with the slack api for learning purposes and getting people to contribute Reason for this Project: Bots are very versatile

null 1 Nov 24, 2021
Messing around with GitHub API to look at omicron build times

gh-workflow-runs This is a very simple tool to dump out basic information about workflow runs for a GitHub repo. The structure is based on gh-subscrip

David Pacheco 1 Nov 30, 2021