API reference¶
Client¶
-
class
pluralkit.Client(token=None, *, async_mode=True, user_agent=None)¶ Represents a client that interacts with the PluralKit API.
- Parameters
token (
Optional[str]) – The PluralKit authorization token, received by thepk;tokencommand.- Keyword Arguments
async_mode – Whether the client runs asynchronously (
True, default) or not (False).user_agent – The User-Agent header to use with the API.
-
id¶ The five-letter lowercase ID of one’s system if an authorization token is provided.
- Type
Optional[str]
-
delete_member(member_id)¶ Deletes a member of one’s system
Note
The system’s authorization token must be set in order to use this method.
-
edit_member(member_id, member=None, **kwargs)¶ Edits a member of one’s system.
Note
The system’s authorization token must be set in order to use this method.
If a
Memberobject is provided, this method will use the attributes of that object to edit the member. If both a Member object and some keyword arguments are passed, the keyword arguments will take priority.- Parameters
member_id (
Union[str,Member]) – The member to be edited. Can be a Member object or the member ID as a string.member (
Optional[Member]) – Optional Member object representing the member with updated attributes.**kwargs – Any number of keyworded patchable values from PluralKit’s member model.
Note
Any fields not passed will retain their prior value. Any fields passed with
Nonewill clear or reset to the default.- Keyword Arguments
name (str) – New name of the member.
display_name (Optional[str]) – New display name of the member. If
Noneis passed, this field is cleared.description (Optional[str]) – New description of the member. If
Noneis passed, this field is cleared.pronouns (Optional[str]) – New pronouns of the member. If
Noneis passed, this field is cleared.color (Union[Color,str,None]) – New color of the member. If a string, must be formatted as a 6-character hex string (e.g.
"ff7000"), sans the # symbol. IfNoneis passed, this field is cleared.avatar_url (Optional[str]) – New avatar URL for the member. If
Noneis passed, this field is cleared.birthday (Union[Birthday,str]) – New birthdate of the member. If a string, must be formatted as
YYYY-MM-DD, in which case, a year of0001or0004represents a hidden year. IfNoneis passed, this field is cleared.proxy_tags (Union[ProxyTags,Sequence[ProxyTag],Sequence[Dict[str,str]]]) – New proxy tags of the member. May be a
ProxyTagsobject, a sequence ofProxyTagobjects, or a sequence of Python dictionaries with the keys “prefix” and “suffix”.keep_proxy (bool) – New truth value for whether to display the member’s proxy tags in the proxied message.
visibility (Union[Privacy,str,None]) – New visibility privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.name_privacy (Union[Privacy,str,None]) – New name privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.description_privacy (Union[Privacy,str,None]) – New description privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.avatar_privacy (Union[Privacy,str,None]) – New avatar privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.pronoun_privacy (Union[Privacy,str]) – New pronouns privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.metadata_privacy (Union[Privacy,str]) – New metadata (eg. creation timestamp, message count, etc.) privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. IfNoneis passed, this field is reset to public.
- Returns
The updated member.
- Return type
-
edit_system(system=None, **kwargs)¶ Edits one’s own system
Note
The system’s authorization token must be set in order to use this method.
If a
Systemobject is provided, this method will use the attributes of that object to edit one’s system. If both a System object and some keyword arguments are passed, the keyword arguments will take priority.- Parameters
system (
Optional[System]) – The optional object to transfer system attributes from.**kwargs – Any number of keyworded patchable values from PluralKit’s system model.
Note
Any fields not passed will retain their prior value. Any fields passed with
Nonewill clear or reset to the default.- Keyword Arguments
name (Optional[str]) – The new system name.
description (Optional[str]) – The new system description.
tag (Optional[str]) – The new system tag.
avatar_url (Optional[str]) – The new system avatar.
tz (Union[Timezone,str,None]) – The timezone as a tzdb identifier. Passing
Nonewill reset this field to “UTC”.description_privacy (Union[Privacy,str,None]) – The new system description privacy.
member_list_privacy (Union[Privacy,str,None]) – The new system member list privacy.
front_privacy (Union[Privacy,str,None]) – The new system front privacy.
metadata_privacy (Union[Privacy,str,None]) – The new system metadata privacy.
- Returns
The updated system.
- Return type
-
get_fronters(system=None)¶ Fetches the current fronters of a system.
- Parameters
system (Optional[Union[str,System,int]]) – The system to fetch fronters from. Can be a System object, the five-letter lowercase system ID as a string, or the Discord user ID corresponding to a system. If
None, fetches the fronters of the system associated with the client.
Note
Passing a Discord user ID takes an extra request. For this reason, it’s perhaps better practice to cache the system ID associated with Discord accounts using
Client.get_systemfirst.
-
get_member(member_id)¶ Gets a system member.
-
get_members(system=None)¶ Retrieve list of a system’s members.
- Parameters
system (Optional[Union[str,System,int]]) – The system to fetch members from. Can be a System object, the five-letter lowercase system ID as a string, or the Discord user ID corresponding to a system. If
None, fetches the members of the system associated with the client.
Note
Passing a Discord user ID takes an extra request. For this reason, it’s perhaps better practice to cache the system ID associated with Discord accounts using
Client.get_systemfirst.- Yields
Member – The next system member.
- Return type
Union[List[Member],AsyncGenerator[Member,None]]
-
get_message(message)¶ Fetches a message proxied by pluralkit
Note
Messages proxied by pluralkit can be fetched either with the proxy message’s id, or the id of the original message that triggered the proxy.
- Parameters
Message – The message to be fetched. Can be a Discord message ID (as a string or integer) or a Message object.
- Returns
The message object.
- Return type
-
get_switches(system=None)¶ Fetches the switch history of a system.
- Parameters
system (
Union[System,str,None]) – The system to fetch switch history from. Can be a System object, the five-letter lowercase system ID as a string, or the Discord user ID corresponding to a system. IfNone, fetches the switch history of the system associated with the client.
Note
Passing a Discord user ID takes an extra request. For this reason, it’s perhaps better practice to cache the system ID associated with Discord accounts using
Client.get_systemfirst.- Yields
Switch – The next switch.
- Return type
Union[List[Switch],AsyncGenerator[Switch,None]]
-
get_system(system=None)¶ Return a system by its system ID or Discord user ID.
-
new_member(name, **kwargs)¶ Creates a new member of one’s system.
Note
The system’s authorization token must be set in order to use this method.
- Parameters
name (
str) – Name of the new member.**kwargs – Any number of keyworded patchable values from PluralKit’s member model.
- Keyword Arguments
display_name (Optional[str]) – New display name of the member. Default is None.
description (Optional[str]) – New description of the member. Default is None.
pronouns (Optional[str]) – New pronouns of the member. Default is None.
color (Union[Color,str,None]) – New color of the member. If a string, must be formatted as a 6-character hex string (e.g.
"ff7000"), sans the # symbol. Default isNone.avatar_url (Optional[str]) – New avatar URL for the member. Default is None.
birthday (Union[Timestamp,str]) – New birthdate of the member. If a string, must be formatted as
YYYY-MM-DD, in which case, year of0001or0004represents a hidden year. Default is None.proxy_tags (Union[ProxyTags,Sequence[ProxyTag],Sequence[Dict[str,str]]]) – New proxy tags of the member. May be a
ProxyTagsobject, a sequence ofProxyTagobjects, or a sequence of Python dictionaries with the keys “prefix” and “suffix”. Default is an empty set of proxy tags.keep_proxy (bool) – New truth value for whether to display the member’s proxy tags in the proxied message. Default is
False.visibility (Union[Privacy,str,None]) – New visibility privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.name_privacy (Union[Privacy,str,None]) – New name privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.description_privacy (Union[Privacy,str,None]) – New description privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.avatar_privacy (Union[Privacy,str,None]) – New avatar privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.pronoun_privacy (Union[Privacy,str]) – New pronouns privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.metadata_privacy (Union[Privacy,str]) – New metadata (eg. creation timestamp, message count, etc.) privacy for the member. Must be either
Privacy.PUBLICorPrivacy.PRIVATE. Default is public.
- Returns
The new member.
- Return type
Models¶
Birthday¶
-
class
pluralkit.Birthday(dt=None, *, year=None, month=None, day=None, hour=0, minute=0, second=0, microsecond=0)¶ Represents a birthday.
Whether this birthday’s year is hidden.
If set to
False, sets the birthday’s year to0001, which internally represents a hidden year in PluralKit’s API.- Return type
Color¶
-
class
pluralkit.Color(*args, **kwargs)¶ Represents a color.
This class is initialized in the same way that a colour.Color object is. It may also take a colour.Color object directly.
-
json()¶ Returns the hex of the
Colorsans the#symbol.Example:
Color("magenta").json()would return"ff00ff".
-
staticmethod
parse(c)¶ Takes in a
Color, colour.Color, or str and converts toColoras needed.- Parameters
color (Union[Color,colour.Color,str,None]) – The color, represented as a
Color, colour.Color orstr. If a string, may either be in the format as expected by PluralKit’s API internally (e.g.00ffff) or a color string that can be taken by a Color object (e.g.cyan).- Returns
The
Colorobject, orNoneif input is None.- Return type
Optional[Color]
- Raises
TypeError – If the given argument is neither a
Color, colour.Color, orstr.
-
Member¶
-
class
pluralkit.Member(*, id, name, created, name_privacy=<Privacy.PUBLIC: 'public'>, display_name=None, description=None, description_privacy=<Privacy.PUBLIC: 'public'>, color=None, birthday=None, birthday_privacy=<Privacy.PUBLIC: 'public'>, pronouns=None, pronoun_privacy=<Privacy.PUBLIC: 'public'>, avatar_url=None, avatar_privacy=<Privacy.PUBLIC: 'public'>, keep_proxy=False, metadata_privacy=<Privacy.PUBLIC: 'public'>, proxy_tags=None, visibility=<Privacy.PUBLIC: 'public'>)¶ Represents a PluralKit system member.
- Parameters
id (
str) – The member’s five-letter lowercase ID.name (
str) – The member’s name.created (
Union[None,Timestamp,datetime,str]) – The member’s creation date. May be a string formatted as{year}-{month}-{day}T{hour}:{minute}:{second}.{microsecond}Z(ISO 8601 format), aTimestamp, or a datetime.name_privacy (
Union[Privacy,str]) – The member’s name privacy, eitherPUBLICorPRIVATE. Default is public.display_name (
Optional[str]) – The member’s display name. Default isNone.description (
Optional[str]) – The member’s description. Default isNone.description_privacy (
Union[Privacy,str]) – The member’s description privacy, eitherPUBLICorPRIVATE. Default is public.color (
Union[Color,str,None]) – The member’s color. Default isNone.birthday (
Union[Birthday,datetime,str,None]) – The member’s birthdate. May be a string formatted as{year}-{month}-{day}, aTimestamp, or a datetime. Default isNone.birthday_privacy (
Union[Privacy,str]) – The member’s birthdate privacy, eitherPUBLICorPRIVATE. Default is public.pronouns (
Optional[str]) – The member’s pronouns. Default isNone.pronoun_privacy (
Union[Privacy,str]) – The member’s pronouns privacy, eitherPUBLICorPRIVATE. Default is public.avatar_privacy (
Union[Privacy,str]) – The member’s avatar privacy, eitherPUBLICorPRIVATE. Default is public.keep_proxy (
bool) – Whether the member’s proxy tags remain in the proxied message (True) or not (False). Default isFalse.metadata_privacy (
Union[Privacy,str]) – The member’s metadata (eg. creation timestamp, message count, etc.) privacy. Must be eitherPUBLICorPRIVATE. Default is public.proxy_tags (
Optional[ProxyTags]) – The member’s proxy tags. Default is an empty set of proxy tags.visibility (
Union[Privacy,str]) – The visibility privacy setting of the member, eitherPUBLICorPRIVATE. Default is public.
-
keep_proxy¶ Whether the member’s proxy tags remain in the proxied message (
True) or not (False).- Type
-
metadata_privacy¶ The member’s metadata (eg. creation timestamp, message count, etc.) privacy.
- Type
The member’s proxy tags.
- Type
-
staticmethod
from_json(member)¶
Message¶
-
class
pluralkit.Message(*, timestamp, id, original, sender, channel, system, member)¶ Represents a proxied message.
- Parameters
timestamp (
Union[Timestamp,datetime,str]) – Timestamp of the message. May be a string for atted as{year}-{month}-{day}T{hour}:{minute}:{second}.{microsecond}Z(ISO 8601 format), aTimestamp, or a datetime.id (
Union[int,str]) – The ID of the Discord message sent by the webhook.original (
Union[int,str]) – The ID of the (presumably deleted) original Discord message sent by the account.sender (
Union[int,str]) – The user ID of the account that sent the message.channel (
Union[int,str]) – The ID of the channel the message was sent to.system (
System) – The system that proxied the message.member (
Member) – The member that proxied the message.
ProxyTag¶
ProxyTags¶
-
class
pluralkit.ProxyTags(proxy_tags=None)¶ Represents a set of PluralKit proxy tags.
Hint
ProxyTags objects can be iterated or indexed to yield its underlying
ProxyTagobjects.-
staticmethod
from_json(proxy_tags)¶ Static method to convert a list of proxy tags
dict`s to a `ProxyTagsobject.
-
staticmethod
Switch¶
-
class
pluralkit.Switch(*, timestamp, members)¶ Represents a switch event.
- Parameters
timestamp (
Union[Timestamp,str]) – Timestamp of the switch. May be a string formatted as{year}-{month}-{day}T{hour}:{minute}:{second}.{microsecond}Z(ISO 8601 format), aTimestamp, or a datetime.members (
Union[Sequence[str],Sequence[Member]]) – Members involved. May be a list of the five-letter member IDs as strings, or a list ofMembermodels, though cannot be mixed.
System¶
-
class
pluralkit.System(*, id, created, name=None, description=None, tag=None, avatar_url=None, tz='UTC', description_privacy=<Privacy.PUBLIC: 'public'>, member_list_privacy=<Privacy.PUBLIC: 'public'>, front_privacy=<Privacy.PUBLIC: 'public'>, front_history_privacy=<Privacy.PUBLIC: 'public'>)¶ Represents a PluralKit system.
- Parameters
id (
str) – The system’s five-character lowercase ID.created (
Union[Timestamp,datetime,str]) – The system’s creation date. May be a string formatted as{year}-{month}-{day}T{hour}:{minute}:{second}.{microsecond}Z(ISO 8601 format), aTimestamp, or a datetime.name (
Optional[str]) – The name of the system. DefaultNone.description (
Optional[str]) – The description of the system. DefaultNone.tag (
Optional[str]) – The system’s tag appended to display names. DefaultNone.avatar_url (
Optional[str]) – The system’s avatar URL. DefaultNone.tz (
Union[Timezone,tzinfo,str]) – The system’s tzdb timezone. May be aTimezone,tzinfo, orstr. Default is"UTC".description_privacy (
Union[Privacy,str]) – The system’s description privacy, eitherPUBLICorPRIVATE. Default is public.member_list_privacy (
Union[Privacy,str]) – The system’s member list privacy, eitherPUBLICorPRIVATE. Default is public.front_privacy (
Union[Privacy,str]) – The system’s fronting privacy, eitherPUBLICorPRIVATE. Default is public.front_history_privacy (
Union[Privacy,str]) – The system’s fronting history privacy, eitherPUBLICorPRIVATE. Default is public.
-
staticmethod
from_json(system)¶
Timestamp¶
-
class
pluralkit.Timestamp(dt=None, *, year=None, month=None, day=None, hour=0, minute=0, second=0, microsecond=0)¶ Represents a PluralKit UTC timestamp.
This class works by wrapping around a
datetimeobject. Usets.datetimeto access it, for anyTimestampts.This class may be initialized in the same way that a
datetimeobject is. It may also take adatetimeobject directly.-
staticmethod
from_json(bd)¶ Takes in a string (as returned by the API) and returns the corresponding
Timestamp.
-
json()¶ Convert this timestamp to the ISO 8601 format that PluralKit uses internally.
- Return type
-
staticmethod
Timezone¶
-
class
pluralkit.Timezone(*args, **kwargs)¶ Represents a tzdb time zone.
This class is initialized in the same way that pytz.timezone initializes
tzinfoobjects. It may also take atzinfoobject directly.- Parameters
tz (Union[str,tzinfo]) – The timezone, either as a string or as a
tzinfo(e.g. from pytz.timezone).
-
staticmethod
from_json(tz)¶ Takes in a string (as returned by the API) and returns the Timezone.
-
json()¶ Returns the string representation of this timezone as expected by the API.
Enumerations¶
Privacy¶
-
class
pluralkit.Privacy(value)¶ Represents the privacies accepted by PluralKit.
-
PUBLIC= 'public'¶ Represents a public PluralKit privacy setting.
-
PRIVATE= 'private'¶ Represents a private PluralKit privacy setting.
-
UNKNOWN= None¶ Equivalent to
Privacy.PUBLICin effect. Returned for member and system privacy fields if the client does not have an authorization token set.
-
Exceptions¶
AuthorizationError¶
-
class
errors.AuthorizationError¶ Thrown when the authorization token passed to PluralKit’s API is invalid (or missing).
DiscordUserNotFound¶
-
class
errors.DiscordUserNotFound(id)¶ Thrown when the Discord user ID is apparently not associated with a PluralKit system.
InvalidBirthday¶
-
class
errors.InvalidBirthday(string)¶ Thrown when an invalid string is passed for the “Birthday” field of a member object. (Must be yyyy-mm-dd)
InvalidKwarg¶
-
class
errors.InvalidKwarg(key)¶ Thrown when an invalid field is passed in a POST or PATCH request