Skip to content

User

Bases: User_

Interface for interacting with planka Users and their included sub-objects

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

delete

Deletes the user

download_avatar

Download the user's avatar to a file

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 user data

remove_avatar

Remove the user's avatar

set_avatar

Set the user's avatar

update

Updates the user with new values

ATTRIBUTE DESCRIPTION
boards

All boards the user is a member of

TYPE: QueryableList[Board]

cards

All cards assigned to the user in all projects

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

manager_of

All projects the user is a manager of

TYPE: QueryableList[Project]

notifications

All notifications for the user

TYPE: QueryableList[Notification]

projects

All projects the user is a member of

TYPE: QueryableList[Project]

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

boards property

boards: QueryableList[Board]

All boards the user is a member of

RETURNS DESCRIPTION
QueryableList[Board]

Queryable List of all boards the user is a member of

cards property

cards: QueryableList[Card]

All cards assigned to the user in all projects

RETURNS DESCRIPTION
QueryableList[Card]

Queryable List of all cards assigned to the user

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

manager_of property

manager_of: QueryableList[Project]

All projects the user is a manager of

RETURNS DESCRIPTION
QueryableList[Project]

Queryable List of all projects the user is a manager of

notifications property

notifications: QueryableList[Notification]

All notifications for the user

RETURNS DESCRIPTION
QueryableList[Notification]

Queryable List of all notifications for the user

projects property

projects: QueryableList[Project]

All projects the user is a member of

RETURNS DESCRIPTION
QueryableList[Project]

Queryable List of all projects the user is a member of

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

delete

delete() -> User

Deletes the user

Danger

This action is irreversible and cannot be undone

RETURNS DESCRIPTION
User

Deleted user instance

TYPE: User

Source code in src/plankapy/v1/interfaces.py
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
def delete(self) -> User:
    """Deletes the user

    Danger:
        This action is irreversible and cannot be undone

    Returns:
        User: Deleted user instance
    """
    self.refresh()
    route = self.routes.delete_user(id=self.id)
    route()
    return self

download_avatar

download_avatar(path: Path) -> Path | None

Download the user's avatar to a file

PARAMETER DESCRIPTION

path

Path to save the avatar image

TYPE: Path

RAISES DESCRIPTION
ValueError

If the user has no avatar

Source code in src/plankapy/v1/interfaces.py
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
def download_avatar(self, path: Path) -> Path | None:
    """Download the user's avatar to a file

    Args:
        path (Path): Path to save the avatar image

    Raises:
        ValueError: If the user has no avatar
    """
    if self.avatarUrl is None:
        return None

    path = Path(path)
    path.write_bytes(self.routes.handler._get_file(self.avatarUrl))
    return path

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 user data

Source code in src/plankapy/v1/interfaces.py
1328
1329
1330
1331
1332
def refresh(self) -> None:
    """Refreshes the user data
    """
    route = self.routes.get_user(id=self.id)
    self.__init__(**route()['item'])

remove_avatar

remove_avatar() -> None

Remove the user's avatar

Source code in src/plankapy/v1/interfaces.py
1254
1255
1256
1257
def remove_avatar(self) -> None:
    """Remove the user's avatar"""
    with self.editor():
        self.avatarUrl = None

set_avatar

set_avatar(image: Path) -> User

Set the user's avatar

Note

The image path can be a local filepath or a URL.

PARAMETER DESCRIPTION

image

Path to the image file

TYPE: Path

RETURNS DESCRIPTION
User

Updated user instance

TYPE: User

Source code in src/plankapy/v1/interfaces.py
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
def set_avatar(self, image: Path) -> User:
    """Set the user's avatar

    Note:
        The image path can be a local filepath or a URL.

    Args:
        image (Path): Path to the image file

    Returns:
        User: Updated user instance
    """
    route = self.routes.post_user_avatar(id=self.id)
    return User(**route(_file=image)['item']).bind(self.routes)

update

update() -> User
update(user: User) -> User
update(name: str = None, username: str = None, email: str = None, language: str = None, organization: str = None, phone: str = None, avatarUrl: str = None, isAdmin: bool = None, isDeletionLocked: bool = None, isLocked: bool = None, isRoleLocked: bool = None, isUsernameLocked: bool = None, subscribeToOwnCards: bool = None) -> User
update(*args, **kwargs) -> User

Updates the user with new values

PARAMETER DESCRIPTION

name

Name of the user (optional)

TYPE: str

username

Username of the user (optional)

TYPE: str

email

Email of the user (optional)

TYPE: str

language

Language of the user (optional)

TYPE: str

organization

Organization of the user (optional)

TYPE: str

phone

Phone number of the user (optional)

TYPE: str

avatarUrl

Avatar url of the user (optional)

TYPE: str

isAdmin

Whether the user is an admin (optional)

TYPE: bool

isDeletionLocked

Whether the user is deletion locked (optional)

TYPE: bool

isLocked

Whether the user is locked (optional)

TYPE: bool

isRoleLocked

Whether the user is role locked (optional)

TYPE: bool

isUsernameLocked

Whether the user is username locked (optional)

TYPE: bool

subscribeToOwnCards

Whether the user is subscribed to their own cards (optional)

TYPE: bool

ALTERNATE DESCRIPTION

user

User instance to update (required)

TYPE: User

Note

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

RETURNS DESCRIPTION
User

Updated user instance

TYPE: User

Source code in src/plankapy/v1/interfaces.py
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
def update(self, *args, **kwargs) -> User:
    """Updates the user with new values

    Args:
        name (str): Name of the user (optional)
        username (str): Username of the user (optional)
        email (str): Email of the user (optional)
        language (str): Language of the user (optional)
        organization (str): Organization of the user (optional)
        phone (str): Phone number of the user (optional)
        avatarUrl (str): Avatar url of the user (optional)
        isAdmin (bool): Whether the user is an admin (optional)
        isDeletionLocked (bool): Whether the user is deletion locked (optional)
        isLocked (bool): Whether the user is locked (optional)
        isRoleLocked (bool): Whether the user is role locked (optional)
        isUsernameLocked (bool): Whether the user is username locked (optional)
        subscribeToOwnCards (bool): Whether the user is subscribed to their own cards (optional)

    Args: Alternate
        user (User): User instance to update (required)

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

    Returns:
        User: Updated user instance
    """
    overload = parse_overload(
        args, kwargs, 
        model='user', 
        options=('name', 'username', 'email', 'language', 
                 'organization', 'phone', 'avatarUrl', 
                 'isAdmin', 'isDeletionLocked', 'isLocked', 
                 'isRoleLocked', 'isUsernameLocked', 
                 'subscribeToOwnCards'),
        noarg=self)
    route = self.routes.patch_user(id=self.id)
    self.__init__(**route(**overload)['item'])
    return self