py-trello Documentation

repository·master·Indexed 21 days ago

https://github.com/sarumont/py-trello

A Python wrapper for the Trello API that represents Trello objects such as Boards, Lists, and Cards as corresponding Python objects. It provides a TrelloClient for API interaction and includes submodules for managing checklists, attachments, labels, members, organizations, and webhooks.

Tokens
987
Snippets
6
Records
8
Agent score
26%

What's inside py-trello

  1. Overview of py-trello submodules

    master

    The py-trello package is organized into several submodules that map to Trello's API entities. Use these modules to interact with specific parts of your Trello workspace:

    • trello.trelloclient: The primary entry point for interacting with the Trello API.
    • trello.board: Manage Trello boards.
    • trello.trellolist: Manage lists within boards.
    • trello.card: Manage cards within lists.
    • trello.checklist: Manage checklists on cards.
    • trello.attachment: Manage file attachments on cards.
    • trello.label: Manage labels.
    • trello.member: Manage Trello members.
    • trello.organization: Manage Trello organizations.
    • trello.webhook: Manage webhooks for real-time updates.
    • trello.exceptions: Handle API-specific errors.
    • trello.base, trello.compat, trello.util: Internal utility and compatibility modules.
  2. Get your Trello OAuth Token

    master

    To perform the OAuth process, set the following environment variables:

    • TRELLO_API_KEY
    • TRELLO_API_SECRET

    Optionally, set TRELLO_EXPIRATION to a string like 'never' or '1day' (Trello's default is 30 days).

    Run the following command to start the OAuth process:

    python -m trello oauth
  3. Configure environment variables for Trello API

    master

    The following environment variables are used for authentication and configuration:

    VariableDescription
    TRELLO_API_KEYYour Trello API key
    TRELLO_API_SECRETYour Trello API secret
    TRELLO_EXPIRATION(Optional) String defining token expiration (e.g., 'never', '1day')
  4. Run tests for py-trello

    master

    To run the internal test suite, use unittest.

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

    Required environment variables for testing:

    • TRELLO_API_KEY
    • TRELLO_TOKEN
    • TRELLO_TEST_BOARD_COUNT
    • TRELLO_TEST_BOARD_NAME (Must be unique)
    • TRELLO_TEST_STAR_COUNT

    To run tests across multiple Python versions, use tox by running tox from the py-trello directory.

    python -m unittest discover
  5. List and access Trello boards

    master

    Use client.list_boards() to retrieve a list of all boards available to the authenticated user. Each board is represented as a Python object where attributes (like .name) are cached.

    all_boards = client.list_boards()
    last_board = all_boards[-1]
    print(last_board.name)
  6. Work with board lists and cards

    master

    Once you have a board object, you can navigate to its lists and then to the cards within those lists:

    1. Call board.list_lists() to see all lists on a board.
    2. Use board.get_list(list_id) to retrieve a specific list by its ID.
    3. Call list.list_cards() on a list object to iterate through its 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)
  7. Initialize the TrelloClient

    master

    To interact with the Trello API, instantiate a TrelloClient.

    If you are using 3-legged OAuth, you must provide api_key, api_secret, token, and token_secret.

    If you are not using 3-legged OAuth, you can initialize the client using only api_key and api_secret.

    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'
    )