Skip to content

List

Bases: List_

METHOD DESCRIPTION
__eq__

Check if two model instances are equal

__getitem__

Get the value of an attribute

__hash__

Generate a hash for the model instance so it can be used in mappings (dict, set)

__iter__

Iterate over public, assigned model attribute names

bind

Bind routes to the model

create_card

Creates a card in the list

delete

Deletes the list

editor

Context manager for editing the model

json

Dump the model properties to a JSON string

pickle

Pickle the model, preserving as much of its state as possible

refresh

Refreshes the list data

set_color

Sets the color of the list

sort_by_due_date

Sorts cards in the list by due date

sort_by_name

Sorts cards in the list by name

sort_by_newest

Sorts cards in the list by newest first

sort_by_oldest

Sorts cards in the list by oldest first

update

Updates the list with new values

ATTRIBUTE DESCRIPTION
board

Board the list belongs to

TYPE: Board

cards

All cards in the list

TYPE: QueryableList[Card]

created_at

Get the creation date of the model instance

TYPE: datetime | None

deleted_at

Get the deletion date of the model instance

TYPE: datetime | None

link

Get the link to the model instance

TYPE: str | None

routes

Get the routes for the model instance

TYPE: Routes

unique_name

Generate a unique name for the model instance using the last 5 characters of the id

TYPE: str

updated_at

Get the last update date of the model instance

TYPE: datetime | None

board property

board: Board

Board the list belongs to

RETURNS DESCRIPTION
Board

Board instance

TYPE: Board

cards property

cards: QueryableList[Card]

All cards in the list

RETURNS DESCRIPTION
QueryableList[Card]

Queryable List of all cards in the list

created_at property

created_at: datetime | None

Get the creation date of the model instance

RETURNS DESCRIPTION
datetime | None

Optional[datetime]: The creation date of the model instance

deleted_at property

deleted_at: datetime | None

Get the deletion date of the model instance

RETURNS DESCRIPTION
datetime | None

Optional[datetime]: The deletion date of the model instance

link: str | None

Get the link to the model instance

Note

Only Project, Board, and Card models have links.

All other models return None

RETURNS DESCRIPTION
str

The link to the model instance

TYPE: str | None

routes property writable

routes: Routes

Get the routes for the model instance

RETURNS DESCRIPTION
Routes

The routes bound to the model instance

TYPE: Routes

unique_name property

unique_name: str

Generate a unique name for the model instance using the last 5 characters of the id and the name attribute

RETURNS DESCRIPTION
str

The unique name for the model instance in the format {name}_{id[:-5]}

TYPE: str

updated_at property

updated_at: datetime | None

Get the last update date of the model instance

RETURNS DESCRIPTION
datetime | None

Optional[datetime]: The last update date of the model instance

__eq__

__eq__(other: Model) -> bool

Check if two model instances are equal

Note

Compares the hash and class of the model instances

Warning

Does not compare the attributes of the model instances, out of sync models with different attributes can still be equal, it's best to refresh the models before comparing.

PARAMETER DESCRIPTION

other

The other model instance to compare

TYPE: Model

RETURNS DESCRIPTION
bool

True if the model instances are equal, False otherwise

TYPE: bool

Source code in src/plankapy/v1/models.py
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
def __eq__(self, other: Model) -> bool:
    """Check if two model instances are equal

    Note:
        Compares the hash and class of the model instances

    Warning:
        Does not compare the attributes of the model instances, out of sync models
        with different attributes can still be equal, it's best to refresh the models
        before comparing.

    Args:
        other (Model): The other model instance to compare

    Returns:
        bool: True if the model instances are equal, False otherwise
    """
    return isinstance(other, self.__class__) and hash(self) == hash(other)

__getitem__

__getitem__(key) -> Any

Get the value of an attribute

Warning

This is an implementation detail that allows for the unpacking operations in the rest of the codebase, all model attributes are still directly accessible through __getattribute___

Note

Returns None if the attribute is Unset or starts with an underscore

Example
print(model['name'])
>>> "Model Name"

model.name = Unset
print(model['name'])
>>> None
Source code in src/plankapy/v1/models.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
def __getitem__(self, key) -> Any:
    """Get the value of an attribute

    Warning:
        This is an implementation detail that allows for the unpacking operations
        in the rest of the codebase, all model attributes are still directly accessible
        through `__getattribute___`

    Note:
        Returns None if the attribute is `Unset` or starts with an underscore

    Example:
        ```python
        print(model['name'])
        >>> "Model Name"

        model.name = Unset
        print(model['name'])
        >>> None
        ```
    """
    val = self.__dict__[key]
    return val if val is not Unset else None

__hash__

__hash__() -> int

Generate a hash for the model instance so it can be used in mappings (dict, set)

Note

All Models are still mutable, but their ID value is unique

RETURNS DESCRIPTION
int

The hash value of the model instance

TYPE: int

Example
board_map = {
    Board(name="Board 1"): board.,
    Board(name="Board 2"): "Board 2"
}
>>> 1
Source code in src/plankapy/v1/models.py
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
def __hash__(self) -> int:
    """Generate a hash for the model instance so it can be used in mappings (`dict`, `set`)

    Note:
        All Models are still mutable, but their ID value is unique

    Returns:
        int: The hash value of the model instance

    Example:
        ```python
        board_map = {
            Board(name="Board 1"): board.,
            Board(name="Board 2"): "Board 2"
        }
        >>> 1
        ```
    """
    if hasattr(self, 'id'):
        return int(self.id)

    # Default hash if no id (string of name and attributes)
    return hash(f"{self.__class__.__name__}{self.__dict__}")

__iter__

__iter__()

Iterate over public, assigned model attribute names

Warning

This is used in conjunction with __getitem__ to unpack assigned values. This allows model state to be passed as keyword arguments to functions

Example:

model = Model(name="Model Name", position=1, other=Unset)

def func(name=None, position=None):
    return {"name": name, "position": position}

print(func(**model))
>>> {'name': 'Model Name', 'position': 1}
Notice how only the assigned values are returned after unpacking and any Unset or private attributes are skipped, This allows None values to be assigned during a PATCH request to delete data

Note

Skips attributes that are Unset or start with an underscore

RETURNS DESCRIPTION
Iterator

The iterator of the model attributes

Example
# Skip Private attributes
print(list(model.__dict__))
>>> ['_privateattribute', 'name', 'position', 'id']

print(list(model))
>>> ['name', 'position', 'id'] # Skips _privateattribute

# Skip Unset attributes
print(model.___dict___)
>>> {'_privateattribute': 'Private', 'name': 'Model Name', 'position': Unset, 'id': 1}

items = dict(model.items())
print(items)
>>> {'name': 'Model Name', 'id': 1} # Skips position because it's Unset
Source code in src/plankapy/v1/models.py
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
def __iter__(self):
    """Iterate over public, assigned model attribute names

    Warning:
        This is used in conjunction with `__getitem__` to unpack assigned values. 
        This allows model state to be passed as keyword arguments to functions

        Example:
            ```python
            model = Model(name="Model Name", position=1, other=Unset)

            def func(name=None, position=None):
                return {"name": name, "position": position}

            print(func(**model))
            >>> {'name': 'Model Name', 'position': 1}
            ```
        Notice how only the assigned values are returned after unpacking and any Unset or 
        private attributes are skipped, This allows `None` values to be assigned during
        a `PATCH` request to delete data 

    Note:
        Skips attributes that are `Unset` or start with an underscore

    Returns:
        Iterator: The iterator of the model attributes

    Example:
        ```python

        # Skip Private attributes
        print(list(model.__dict__))
        >>> ['_privateattribute', 'name', 'position', 'id']

        print(list(model))
        >>> ['name', 'position', 'id'] # Skips _privateattribute

        # Skip Unset attributes
        print(model.___dict___)
        >>> {'_privateattribute': 'Private', 'name': 'Model Name', 'position': Unset, 'id': 1}

        items = dict(model.items())
        print(items)
        >>> {'name': 'Model Name', 'id': 1} # Skips position because it's Unset
        ```
    """
    return iter(
        k for k, v in self.__dict__.items() 
        if v is not Unset 
        and not k.startswith("_")
    )

bind

bind(routes: Routes) -> Self

Bind routes to the model Args: routes (Routes): The routes to bind to the model instance

RETURNS DESCRIPTION
Self

Self for chain operations

Example
model = Model(**kwargs).bind(routes)
Source code in src/plankapy/v1/models.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def bind(self, routes: Routes) -> Self:
    """Bind routes to the model
    Args:
        routes (Routes): The routes to bind to the model instance

    Returns:
        Self for chain operations

    Example:
        ```python
        model = Model(**kwargs).bind(routes)
        ```
    """
    self.routes = routes
    return self

create_card

create_card(card: Card) -> Card
create_card(name: str, position: int = 0, description: str = None, dueDate: datetime = None, isDueDateCompleted: bool = None, stopwatch: Stopwatch = None, boardId: int = None, listId: int = None, creatorUserId: int = None, coverAttachmentId: int = None, isSubscribed: bool = None) -> Card
create_card(*args, **kwargs) -> Card

Creates a card in the list

PARAMETER DESCRIPTION

name

Name of the card (required)

TYPE: str

position

Position of the card (default: 0)

TYPE: int

description

Description of the card (optional)

TYPE: str

dueDate

Due date of the card (optional)

TYPE: datetime

isDueDateCompleted

Whether the due date is completed (optional)

TYPE: bool

stopwatch

Stopwatch of the card (optional)

TYPE: Stopwatch

boardId

Board id of the card (optional)

TYPE: int

listId

List id of the card (optional)

TYPE: int

creatorUserId

Creator user id of the card (optional)

TYPE: int

coverAttachmentId

Cover attachment id of the card (optional)

TYPE: int

isSubscribed

Whether the card is subscribed (optional)

TYPE: bool

ALTERNATE DESCRIPTION

card

Card instance to create

TYPE: Card

RETURNS DESCRIPTION
Card

New card instance

TYPE: Card

Source code in src/plankapy/v1/interfaces.py
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
def create_card(self, *args, **kwargs) -> Card:
    """Creates a card in the list

    Args:
        name (str): Name of the card (required)
        position (int): Position of the card (default: 0)
        description (str): Description of the card (optional)
        dueDate (datetime): Due date of the card (optional)
        isDueDateCompleted (bool): Whether the due date is completed (optional)
        stopwatch (Stopwatch): Stopwatch of the card (optional)
        boardId (int): Board id of the card (optional)
        listId (int): List id of the card (optional)
        creatorUserId (int): Creator user id of the card (optional)
        coverAttachmentId (int): Cover attachment id of the card (optional)
        isSubscribed (bool): Whether the card is subscribed (optional)

    Args: Alternate
        card (Card): Card instance to create

    Returns:
        Card: New card instance
    """
    overload = parse_overload(
        args, kwargs, 
        model='card', 
        options=('name', 'position', 'description', 'dueDate', 
                'isDueDateCompleted', 'stopwatch', 
                'creatorUserId', 'coverAttachmentId', 
                'isSubscribed'), 
        required=('name',))

    overload['boardId'] = self.boardId
    overload['listId'] = self.id
    overload['position'] = overload.get('position', 0)

    route = self.routes.post_card(id=self.id)
    return Card(**route(**overload)['item']).bind(self.routes)

delete

delete() -> List

Deletes the list

Danger

This action is irreversible and cannot be undone

RETURNS DESCRIPTION
List

Deleted list instance

TYPE: List

Source code in src/plankapy/v1/interfaces.py
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
def delete(self) -> List:
    """Deletes the list

    Danger:
        This action is irreversible and cannot be undone

    Returns:
        List: Deleted list instance
    """
    self.refresh()
    route = self.routes.delete_list(id=self.id)
    route()
    return self

editor

editor() -> Generator[Self, None, None]

Context manager for editing the model

Example
print(model.name)
>>> "Old Name"
with model.editor() as m:
    m.name = "New Name"
    m.position = 1

print(model.name)
>>> "New Name"
Source code in src/plankapy/v1/models.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
@contextmanager
def editor(self) -> Generator[Self, None, None]:
    """Context manager for editing the model

    Example:
        ```python
        print(model.name)
        >>> "Old Name"
        with model.editor() as m:
            m.name = "New Name"
            m.position = 1

        print(model.name)
        >>> "New Name"
        ```

    """
    try:
        self.refresh()
        _self = self.__dict__.copy() # Backup the model state
        yield self
    except Exception as e:
        self.__dict__ = _self # Restore the model state
        raise e
    finally:
        self.update()

json

json() -> str

Dump the model properties to a JSON string

Note

Only properties defined in the {Model}_ dataclass are dumped. All relationships and included items (e.g. board.cards) are lost. If you wish to preserve these relationships, use the .pickle method

RETURNS DESCRIPTION
str

(str) : A JSON string with the Model attributes

Source code in src/plankapy/v1/models.py
132
133
134
135
136
137
138
139
140
141
142
143
def json(self) -> str:
    """Dump the model properties to a JSON string

    Note:
        Only properties defined in the `{Model}_` dataclass are dumped. 
        All relationships and included items (e.g. `board.cards`) are lost.
        If you wish to preserve these relationships, use the `.pickle` method

    Returns:
        (str) : A JSON string with the Model attributes
    """
    return json.dumps({k: self[k] for k in self})

pickle

pickle() -> bytes

Pickle the model, preserving as much of its state as possible

Warning

This method currently works, and since the object data is updated by routes You can use this to store a reference to a specific object. The data will be maintained until operations that trigger a .refresh() call are made, e.g. using the .editor() context.

RETURNS DESCRIPTION
bytes

(bytes) : Raw bytes generated by pickle.dump

Source code in src/plankapy/v1/models.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def pickle(self) -> bytes:
    """Pickle the model, preserving as much of its state as possible

    Warning:
        This method currently works, and since the object data is updated by routes
        You can use this to store a reference to a specific object. The data will be
        maintained until operations that trigger a `.refresh()` call are made, e.g. 
        using the `.editor()` context.

    Returns:
        (bytes) : Raw bytes generated by `pickle.dump`
    """
    out = io.BufferedWriter(raw=io.BytesIO())
    pickle.dump(self, out)
    return out.raw.read()

refresh

refresh() -> None

Refreshes the list data

Source code in src/plankapy/v1/interfaces.py
2538
2539
2540
2541
2542
def refresh(self) -> None:
    """Refreshes the list data"""
    for _list in self.board.lists:
        if _list.id == self.id:
            self.__init__(**_list)

set_color

set_color(color: ListColors) -> List

Sets the color of the list

Note

This method is only available in Planka 2.0.0 and later

PARAMETER DESCRIPTION

color

Color of the list

TYPE: str

RETURNS DESCRIPTION
List

The list instance with the color set

TYPE: List

Source code in src/plankapy/v1/interfaces.py
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
def set_color(self, color: ListColors) -> List:
    """Sets the color of the list

    Note:
        This method is only available in Planka 2.0.0 and later

    Args:
        color (str): Color of the list

    Returns:
        List: The list instance with the color set
    """
    if color not in ListColors.__args__:
        raise ValueError(
            f"Invalid color: {color}\n"
            f"Valid colors: {ListColors.__args__}")
    with self.editor():
        self.color = color
    return self

sort_by_due_date

sort_by_due_date() -> None

Sorts cards in the list by due date

Note

After sorting, a call to list.cards will return a sorted list of cards

Source code in src/plankapy/v1/interfaces.py
2452
2453
2454
2455
2456
2457
2458
def sort_by_due_date(self) -> None:
    """Sorts cards in the list by due date

    Note:
        After sorting, a call to `list.cards` will return a sorted list of cards
    """
    self._sort('Due date')

sort_by_name

sort_by_name() -> None

Sorts cards in the list by name

Note

After sorting, a call to list.cards will return a sorted list of cards

Source code in src/plankapy/v1/interfaces.py
2444
2445
2446
2447
2448
2449
2450
def sort_by_name(self) -> None:
    """Sorts cards in the list by name

    Note:
        After sorting, a call to `list.cards` will return a sorted list of cards
    """
    self._sort('Name')

sort_by_newest

sort_by_newest() -> None

Sorts cards in the list by newest first

Note

After sorting, a call to list.cards will return a sorted list of cards

Source code in src/plankapy/v1/interfaces.py
2460
2461
2462
2463
2464
2465
2466
def sort_by_newest(self) -> None:
    """Sorts cards in the list by newest first

    Note:
        After sorting, a call to `list.cards` will return a sorted list of cards
    """
    self._sort('Newest First')

sort_by_oldest

sort_by_oldest() -> None

Sorts cards in the list by oldest first

Note

After sorting, a call to list.cards will return a sorted list of cards

Source code in src/plankapy/v1/interfaces.py
2468
2469
2470
2471
2472
2473
2474
def sort_by_oldest(self) -> None:
    """Sorts cards in the list by oldest first

    Note:
        After sorting, a call to `list.cards` will return a sorted list of cards
    """
    self._sort('Oldest First')

update

update() -> List
update(list: List) -> List
update(name: str = None, position: int = None) -> List
update(*args, **kwargs) -> List

Updates the list with new values

Tip

If you want to update a list, it's better to use the editor() context manager

Example:

>>> with list_.editor():
...    list_.name = 'New List Name'
...    list_.position = 1

>>> list
List(id=1, name='New List Name', position=1, ...)

PARAMETER DESCRIPTION

name

Name of the list (optional)

TYPE: str

position

Position of the list (optional)

TYPE: int

ALTERNATE DESCRIPTION

list

List instance to update (required)

TYPE: List

Note

If no arguments are provided, the list will update itself with the current values stored in its attributes

RETURNS DESCRIPTION
List

Updated list instance

TYPE: List

Source code in src/plankapy/v1/interfaces.py
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
def update(self, *args, **kwargs) -> List:
    """Updates the list with new values

    Tip:
        If you want to update a list, it's better to use the `editor()` context manager

        Example:
        ```python
        >>> with list_.editor():
        ...    list_.name = 'New List Name'
        ...    list_.position = 1

        >>> list
        List(id=1, name='New List Name', position=1, ...)
        ```

    Args:
        name (str): Name of the list (optional)
        position (int): Position of the list (optional)

    Args: Alternate
        list (List): List instance to update (required)

    Note:
        If no arguments are provided, the list will update itself with the current values stored in its attributes

    Returns:
        List: Updated list instance
    """
    overload = parse_overload(
        args, kwargs, 
        model='list', 
        options=('name', 'position'),
        noarg=self)

    route = self.routes.patch_list(id=self.id)
    self.__init__(**route(**overload)['item'])
    return self