v1 pluralkit.py API reference¶
Client¶
- class pluralkit.v1.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;token
command.- 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
Member
object 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:
Note
Any fields not passed will retain their prior value. Any fields passed with
None
will 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
None
is passed, this field is cleared.description (Optional[str]) – New description of the member. If
None
is passed, this field is cleared.pronouns (Optional[str]) – New pronouns of the member. If
None
is 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. IfNone
is passed, this field is cleared.avatar_url (Optional[str]) – New avatar URL for the member. If
None
is 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 of0001
or0004
represents a hidden year. IfNone
is passed, this field is cleared.proxy_tags (Union[ProxyTags,Sequence[ProxyTag],Sequence[Dict[str,str]]]) – New proxy tags of the member. May be a
ProxyTags
object, a sequence ofProxyTag
objects, 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.PUBLIC
orPrivacy.PRIVATE
. IfNone
is passed, this field is reset to public.name_privacy (Union[Privacy,str,None]) – New name privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. IfNone
is passed, this field is reset to public.description_privacy (Union[Privacy,str,None]) – New description privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. IfNone
is passed, this field is reset to public.avatar_privacy (Union[Privacy,str,None]) – New avatar privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. IfNone
is passed, this field is reset to public.pronoun_privacy (Union[Privacy,str]) – New pronouns privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. IfNone
is 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.PUBLIC
orPrivacy.PRIVATE
. IfNone
is 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
System
object 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
None
will 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
None
will 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_system
first.
- 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_system
first.
- 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_system
first.
- 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 of0001
or0004
represents 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
ProxyTags
object, a sequence ofProxyTag
objects, 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.PUBLIC
orPrivacy.PRIVATE
. Default is public.name_privacy (Union[Privacy,str,None]) – New name privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. Default is public.description_privacy (Union[Privacy,str,None]) – New description privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. Default is public.avatar_privacy (Union[Privacy,str,None]) – New avatar privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.PRIVATE
. Default is public.pronoun_privacy (Union[Privacy,str]) – New pronouns privacy for the member. Must be either
Privacy.PUBLIC
orPrivacy.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.PUBLIC
orPrivacy.PRIVATE
. Default is public.
- Returns:
The new member.
- Return type:
Models¶
Birthday¶
- class pluralkit.v1.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.v1.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
Color
sans the#
symbol.Example:
Color("magenta").json()
would return"ff00ff"
.
- staticmethod parse(c)¶
Takes in a
Color
, colour.Color, or str and converts toColor
as 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
Color
object, orNone
if input is None.- Return type:
Optional[Color]
- Raises:
TypeError – If the given argument is neither a
Color
, colour.Color, orstr
.
Member¶
- class pluralkit.v1.Member(*, id, name, created, name_privacy=Privacy.PUBLIC, display_name=None, description=None, description_privacy=Privacy.PUBLIC, color=None, birthday=None, birthday_privacy=Privacy.PUBLIC, pronouns=None, pronoun_privacy=Privacy.PUBLIC, avatar_url=None, avatar_privacy=Privacy.PUBLIC, keep_proxy=False, metadata_privacy=Privacy.PUBLIC, proxy_tags=None, visibility=Privacy.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, eitherPUBLIC
orPRIVATE
. 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, eitherPUBLIC
orPRIVATE
. 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, eitherPUBLIC
orPRIVATE
. Default is public.pronouns (
Optional
[str
]) – The member’s pronouns. Default isNone
.pronoun_privacy (
Union
[Privacy
,str
]) – The member’s pronouns privacy, eitherPUBLIC
orPRIVATE
. Default is public.avatar_privacy (
Union
[Privacy
,str
]) – The member’s avatar privacy, eitherPUBLIC
orPRIVATE
. 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 eitherPUBLIC
orPRIVATE
. 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, eitherPUBLIC
orPRIVATE
. 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:
- staticmethod from_json(member)¶
Message¶
- class pluralkit.v1.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.
- original¶
The ID of the (presumably deleted) original Discord message sent by the account.
- Type:
ProxyTag¶
Switch¶
- class pluralkit.v1.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 ofMember
models, though cannot be mixed.
System¶
- class pluralkit.v1.System(*, id, created, name=None, description=None, tag=None, avatar_url=None, tz='UTC', description_privacy=Privacy.PUBLIC, member_list_privacy=Privacy.PUBLIC, front_privacy=Privacy.PUBLIC, front_history_privacy=Privacy.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, eitherPUBLIC
orPRIVATE
. Default is public.member_list_privacy (
Union
[Privacy
,str
]) – The system’s member list privacy, eitherPUBLIC
orPRIVATE
. Default is public.front_privacy (
Union
[Privacy
,str
]) – The system’s fronting privacy, eitherPUBLIC
orPRIVATE
. Default is public.front_history_privacy (
Union
[Privacy
,str
]) – The system’s fronting history privacy, eitherPUBLIC
orPRIVATE
. Default is public.
- staticmethod from_json(system)¶
Timestamp¶
- class pluralkit.v1.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
datetime
object. Usets.datetime
to access it, for anyTimestamp
ts
.This class may be initialized in the same way that a
datetime
object is. It may also take adatetime
object 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:
Timezone¶
- class pluralkit.v1.Timezone(*args, **kwargs)¶
Represents a tzdb time zone.
This class is initialized in the same way that pytz.timezone initializes
tzinfo
objects. It may also take atzinfo
object 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.v1.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.PUBLIC
in effect. Returned for member and system privacy fields if the client does not have an authorization token set.
Exceptions¶
PluralKitException¶
- class pluralkit.v1.errors.PluralKitException¶
Base exception class for pk.py
AccessForbidden¶
- class pluralkit.v1.errors.AccessForbidden¶
Thrown when attempting to access private info.
DiscordUserNotFound¶
- class pluralkit.v1.errors.DiscordUserNotFound(id)¶
Thrown when the Discord user ID is apparently not associated with a PluralKit system.
InvalidBirthday¶
- class pluralkit.v1.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 pluralkit.v1.errors.InvalidKwarg(key)¶
Thrown when an invalid field is passed in a POST or PATCH request
SystemNotFound¶
- class pluralkit.v1.errors.SystemNotFound(id)¶
Thrown when the system ID is apparently not in PluralKit’s database.
MemberNotFound¶
- class pluralkit.v1.errors.MemberNotFound(id)¶
Thrown when the member ID is apparently not in PluralKit’s database.