API reference¶
All classes listed below are imported into the main skpy
namespace, so can be imported without the need to reference submodules (i.e. from skpy import Skype
).
Core classes¶
- class skpy.main.Skype[source]¶
The main Skype instance. Provides methods for retrieving various other object types.
- user¶
Contact information for the connected account.
- Type:
- contacts¶
Container of contacts for the connected user.
- Type:
- chats¶
Container of conversations for the connected user.
- Type:
- settings¶
Read/write access to server-side account options.
- Type:
- translate¶
Connected instance of the translator service.
- Type:
- conn¶
Underlying connection instance.
- Type:
- __init__(user=None, pwd=None, tokenFile=None, connect=True)[source]¶
Create a new Skype object and corresponding connection.
If
user
andpwd
are given, they will be passed toSkypeConnection.setUserPwd()
. This can be either a Skype username/password pair, or a Microsoft account email address and its associated password.If a token file path is present, it will be used if valid. On a successful connection, the token file will also be written to.
By default, a connection attempt will be made if any valid form of credentials are supplied. It is also possible to handle authentication manually, by working with the underlying connection object instead.
- Parameters:
- Raises:
.SkypeAuthException – if connecting, and the login request is rejected
.SkypeApiException – if connecting, and the login form can’t be processed
- getEvents()[source]¶
Retrieve a list of events since the last poll. Multiple calls may be needed to retrieve all events.
If no events occur, the API will block for up to 30 seconds, after which an empty list is returned. As soon as an event is received in this time, it is returned immediately.
- Returns:
a list of events, possibly empty
- Return type:
SkypeEvent
list
- setPresence(status=Online)[source]¶
Set the current user’s presence on the network. Supports
Status.Online
,Status.Busy
orStatus.Hidden
(shown asStatus.Offline
to others).- Parameters:
status (.Status) – new availability to display to contacts
- setMood(mood)[source]¶
Update the activity message for the current user.
- Parameters:
mood (str) – new mood message
- class skpy.main.SkypeEventLoop[source]¶
A skeleton class for producing event processing programs. Implementers will most likely want to override the
onEvent()
method.- __init__(user=None, pwd=None, tokenFile=None, autoAck=True, status=None)[source]¶
Create a new event loop and the underlying connection.
All arguments up to
tokenFile
are passed to theSkypeConnection
instance.
- cycle()[source]¶
Request one batch of events from Skype, calling
onEvent()
with each event in turn.Subclasses may override this method to alter loop functionality.
- loop()[source]¶
Continuously handle any incoming events using
cycle()
.This method does not return, so for programs with a UI, this will likely need to be run in its own thread.
- onEvent(event)[source]¶
A stub method that subclasses should implement to react to messages and status changes.
- Parameters:
event (SkypeEvent) – an incoming event
- class skpy.main.SkypeSettings[source]¶
An interface for getting and setting server options for the connected account.
All attributes are read/write, with values fetched on each access, and implicit server writes when changed.
- notificationPopups¶
Skype for Web (Notifications): show browser notifications on new messages.
- Type:
- webLinkPreviews¶
Skype for Web (Web link previews): replace URLs in messages with rich previews.
- Type:
- youtubePlayer¶
Skype for Web (YouTube player): replace YouTube URLs with an inline player.
- Type:
- mentionNotifs¶
Skype for Web (@mention notifications): trigger notifications when mentioned in a message.
- Type:
- imagePaste¶
Skype for Web (Enable image paste): support sending image files by pasting into a conversation input field.
- Type:
Skype for Web (Typing indicator): send typing notifications to contacts when active in conversations.
- Type:
- emoteSuggestions¶
Skype for Web (Emoticon suggestions): show popup lists of emoticons matching keywords.
- Type:
- showEmotes¶
Skype for Web (Show emoticons): replace text shortcuts (
:)
) with actual emoticons in conversations.- Type:
- animateEmotes¶
Skype for Web (Show animated emoticons): use animated version of emoticons.
- Type:
- largeEmotes¶
Skype for Web (Show large emoticons): if only an emoticon in a message, display it larger.
- Type:
- pinFavourites¶
Skype for Web (Pin recent favorites): show favourite and recent contacts at the top of the contact list.
- Type:
- autoAddFriends¶
Make address book contacts with Skype accounts appear in the contact list.
- Type:
Users and contacts¶
- class skpy.user.SkypeUser[source]¶
A user on Skype – the current one, a contact, or someone else.
Properties differ slightly between the current user and others. Only public properties are available here.
Searches different possible attributes for each property. Also deconstructs a merged first name field.
- chat¶
One-to-one conversation with this user.
- Type:
- class Location[source]¶
The location of a user or contact.
Any number of fields may be filled in, so stringifying will combine them into a comma-separated list.
- classmethod rawToFields(raw={})[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- invite(greeting=None)[source]¶
Send the user a contact request.
- Parameters:
greeting (str) – custom message to include with the request
- class skpy.user.SkypeContact[source]¶
A user on Skype that the logged-in account is a contact of. Allows access to contacts-only properties.
- birthday¶
Date of birth of the user.
- Type:
- classmethod rawToFields(raw={})[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- class skpy.user.SkypeBotUser[source]¶
A server-side bot account. In most cases, they act like a normal user – they can be added as contacts, interacted with in one-to-one conversations, or invited to groups if the bot supports it.
- locales¶
Country-language codes supported by the bot.
- Type:
str list
- class skpy.user.SkypeContacts[source]¶
A container of contacts, providing caching of user info to reduce API requests.
There are multiple ways to look up users in Skype:
Requesting the whole contact list – includes most fields, as well as authorisation status.
Requesting a single contact (
contact()
) – returns all public and contact-private info.Requesting a single user (
user()
) – only provides public information, but works with any user.Searching the Skype directory (
search()
) – returns a collection of search results.
When using key lookups, it checks the contact list first, with a user fallback for non-contacts.
Contacts can also be iterated over, where only authorised users are returned in the collection.
- groups¶
Set of
SkypeContactGroup
instances, keyed by group name.- Type:
- blocked¶
Group of users blocked from all communication.
- Type:
- contact(id)[source]¶
Retrieve all details for a specific contact, including fields such as birthday and mood.
- Parameters:
id (str) – user identifier to lookup
- Returns:
resulting contact object
- Return type:
- bots()[source]¶
Retrieve a list of all known bots.
- Returns:
resulting bot user objects
- Return type:
SkypeBotUser list
- bot(id)[source]¶
Retrieve a single bot.
- Parameters:
id (str) – UUID or username of the bot
- Returns:
resulting bot user object
- Return type:
- search(query)[source]¶
Search the Skype Directory for a user.
- Parameters:
query (str) – name to search for
- Returns:
collection of possible results
- Return type:
SkypeUser list
- requests()[source]¶
Retrieve any pending contact requests.
- Returns:
collection of requests
- Return type:
SkypeRequest
list
- class skpy.user.SkypeContactGroup[source]¶
A user-defined collection of contacts. Currently read-only in the API.
- contacts¶
Contacts added to this group.
- Type:
SkypeContact
list
Conversations¶
- class skpy.chat.SkypeChat[source]¶
A conversation within Skype.
- id¶
Unique identifier of the conversation.
One-to-one chats have identifiers of the form
<type>:<username>
.Cloud group chat identifiers are of the form
<type>:<identifier>@thread.skype
.- Type:
- classmethod rawToFields(raw={})[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- classmethod fromRaw(skype=None, raw={})[source]¶
Create a new instance based on the raw properties of an API response.
This can be overridden to automatically create subclass instances based on the raw content.
- getMsgs()[source]¶
Retrieve a batch of messages from the conversation.
This method can be called repeatedly to retrieve older messages.
If new messages arrive in the meantime, they are returned first in the next batch.
- Returns:
collection of messages
- Return type:
SkypeMsg
list
- sendRaw(editId=None, **kwargs)[source]¶
Send a raw message to the conversation. At a minimum, values for
content
,messagetype
andcontenttype
should be provided.The message object returned here will not have a server-provided identifier (needed for acks), as the messages API does not provide it. Note that message edits depend on the client identifier, which is included.
There is no need to include
clientmessageid
orskypeeditedid
– instead, useeditId
to update an existing message, otherwise a new one will be created with its own client identifier.- Parameters:
editId (int) – identifier of an existing message to replace
content (str) – plain or HTML body for the message
contenttype (str) – format of the message, normally
text
messagetype (str) – base message type
skypeemoteoffset (int) – used with action messages to control where the user’s name ends
Has-Mentions (str) – whether the message mentions any other users
kwargs (dict) – any additional arguments not listed above
- Returns:
copy of the sent message object
- Return type:
.SkypeMsg
- setTyping(active=True)[source]¶
Send a typing presence notification to the conversation. This will typically show the “<name> is typing…” message in others clients.
Note
A user’s event stream will not receive any events for their own typing notifications.
It may be necessary to send this type of message continuously, as each typing presence usually expires after a few seconds. Set
active
toFalse
to clear a current presence.- Parameters:
active (bool) – whether to show as currently typing
- Returns:
copy of the sent message object
- Return type:
.SkypeMsg
- sendMsg(content, me=False, rich=False, edit=None)[source]¶
Send a text message to the conversation.
If
me
is specified, the message is sent as an action (equivalent to/me <content>
in other clients). This is typically displayed as “<name><content>
”, where clicking the name links back to your profile.Rich text can also be sent, provided it is formatted using Skype’s subset of HTML. Helper methods on the
SkypeMsg
class can generate the necessary markup.- Parameters:
- Returns:
copy of the sent message object
- Return type:
.SkypeMsg
- sendFile(content, name, image=False)[source]¶
Upload a file to the conversation. Content should be an ASCII or binary file-like object.
If an image, Skype will generate a thumbnail and link to the full image.
- sendContacts(*contacts)[source]¶
Share one or more contacts with the conversation.
- Parameters:
contacts (SkypeUser list) – users to embed in the message
- Returns:
copy of the sent message object
- Return type:
.SkypeContactMsg
- setConsumption(horizon)[source]¶
Update the user’s consumption horizon for this conversation, i.e. where it has been read up to.
To consume up to a given message, call
SkypeMsg.read()
instead.- Parameters:
horizon (str) – new horizon string, of the form
<id>,<timestamp>,<id>
- class skpy.chat.SkypeGroupChat[source]¶
A group conversation within Skype. Compared to single chats, groups have a topic and participant list.
- active¶
Whether the full group chat was retrieved from the server. This may be
False
if a group conversation still appears in the recent list despite being left or deleted.- Type:
- classmethod rawToFields(raw={}, active=False)[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- setTopic(topic)[source]¶
Update the topic message. An empty string clears the topic.
- Parameters:
topic (str) – new conversation topic
- setModerated(moderated=True)[source]¶
Update the chat type, and make chat moderated.
- Parameters:
moderated (bool) – whether to enable moderation restrictions
- setOpen(open)[source]¶
Enable or disable joining by URL. This does not affect current participants inviting others.
- Parameters:
open (bool) – whether to accept new participants via a public join link
- setHistory(history)[source]¶
Enable or disable conversation history. This only affects messages sent after the change.
If disabled, new participants will not see messages before they arrived.
- Parameters:
history (bool) – whether to provide message history to new participants
- addMember(id, admin=False)[source]¶
Add a user to the conversation, or update their user/admin status.
- class skpy.chat.SkypeChats[source]¶
A container of conversations, providing caching of user info to reduce API requests.
Key lookups allow retrieving conversations by identifier.
- recent()[source]¶
Retrieve a selection of conversations with the most recent activity, and store them in the cache.
Each conversation is only retrieved once, so subsequent calls will retrieve older conversations.
- Returns:
collection of recent conversations keyed by their ID
- Return type:
SkypeChat
dict
- create(members=(), admins=(), moderated=False)[source]¶
Create a new group chat with the given users.
The current user is automatically added to the conversation as an admin. Any other admin identifiers must also be present in the member list.
- Parameters:
members (str list) – user identifiers to initially join the conversation
admins (str list) – user identifiers to gain admin privileges
moderate (bool) – whether to enable moderation restrictions
- Returns:
newly created group conversation
- Return type:
Messages¶
- class skpy.msg.SkypeMsg[source]¶
A message either sent or received in a conversation.
An edit is represented by a follow-up message with the same
clientId
, which replaces the earlier message.- time¶
Original arrival time of the message.
- Type:
- static link(url, display=None)[source]¶
Create a hyperlink. If
display
is not specified, display the URL.Note
Anomalous API behaviour: official clients don’t provide the ability to set display text.
- static mention(user)[source]¶
Mention a user in a message. This may trigger a notification for them even if the conversation is muted.
- mention_all = '<at id="*">all</at>'¶
Mention all users of a group chat in a message.
- static quote(user, chat, timestamp, content)[source]¶
Display a message excerpt as a quote from another user.
Skype for Web doesn’t support native quotes, and instead displays the legacy quote text. Supported desktop clients show a blockquote with the author’s name and timestamp underneath.
Note
Anomalous API behaviour: it is possible to fake the message content of a quote.
- Parameters:
user (SkypeUser) – user who is to be quoted saying the message
chat (SkypeChat) – conversation the quote was originally seen in
timestamp (datetime.datetime) – original arrival time of the quoted message
content (str) – excerpt of the original message to be quoted
- Returns:
tag to display the excerpt as a quote
- Return type:
- static uriObject(content, type, url, thumb=None, title=None, desc=None, **values)[source]¶
Generate the markup needed for a URI component in a rich message.
- Parameters:
- Returns:
<URIObject>
tag- Return type:
- classmethod rawToFields(raw={})[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- classmethod fromRaw(skype=None, raw={})[source]¶
Create a new instance based on the raw properties of an API response.
This can be overridden to automatically create subclass instances based on the raw content.
- edit(content, me=False, rich=False)[source]¶
Send an edit of this message. Arguments are passed to
SkypeChat.sendMsg()
.Note
Anomalous API behaviour: messages can be undeleted by editing their content to be non-empty.
- class skpy.msg.SkypeTextMsg[source]¶
A message containing rich or plain text.
- plain¶
Message content converted to plain text.
Hyperlinks are replaced with their target, quotes are converted to the legacy format, and all other HTML tags are stripped from the text.
- Type:
- markup¶
Message converted to plain text, retaining formatting markup.
Hyperlinks become their target, message edit tags are stripped, and legacy quote text is used.
In addition, the following replacements are made:
Rich text
Plain text
<b>bold</b>
*bold*
<i>italic</i>
_italic_
<s>strikethrough</s>
~strikethrough~
<pre>monospace</pre>
{code}monospace{code}
<at id="8:fred.2">Fred</at>
@fred.2
- Type:
- class skpy.msg.SkypeContactMsg[source]¶
A message containing one or more shared contacts.
- contactNames¶
Names of the users, as seen by the sender of the message.
- Type:
str list
- class skpy.msg.SkypeFileMsg[source]¶
A message containing a file shared in a conversation.
- class skpy.msg.SkypeCallMsg[source]¶
A message representing a change in state to a voice or video call inside the conversation.
- state¶
New state of the call.
- Type:
State
- userNames¶
Names of the users, as seen by the initiator of the call.
- Type:
str list
- class skpy.msg.SkypePropertyMsg[source]¶
A base message type for changes to conversation properties.
- class skpy.msg.SkypeTopicPropertyMsg[source]¶
A message representing a change in a group conversation’s topic.
- class skpy.msg.SkypeOpenPropertyMsg[source]¶
A message representing a change to joining the conversation by link.
- class skpy.msg.SkypeHistoryPropertyMsg[source]¶
A message representing a change to history disclosure.
- class skpy.msg.SkypeMemberMsg[source]¶
A message representing a change in a group conversation’s participants.
Note that Skype represents these messages as being sent by the conversation, rather than the initiator. Instead,
user
is set to the initiator, andmember
to the target.
- class skpy.msg.SkypeAddMemberMsg[source]¶
A message representing a user added to a group conversation.
Events¶
- class skpy.event.SkypeEvent[source]¶
The base Skype event. Pulls out common identifier, time and type parameters.
- time¶
Time at which the event occurred.
- Type:
- classmethod rawToFields(raw={})[source]¶
Convert the raw properties of an API response into class fields. Override to process additional values.
- class skpy.event.SkypePresenceEvent[source]¶
An event for contacts changing status or presence.
- status¶
Chosen availability status.
- Type:
Status
- capabilities¶
Features currently available from this user, across all endpoints.
- Type:
str list
- class skpy.event.SkypeEndpointEvent[source]¶
An event for changes to individual contact endpoints.
- capabilities¶
Features available on the device.
- Type:
str list
- class skpy.event.SkypeTypingEvent[source]¶
An event for users starting or stopping typing in a conversation.
- class skpy.event.SkypeMessageEvent[source]¶
The base message event, when a message is received in a conversation.
- class skpy.event.SkypeNewMessageEvent[source]¶
An event for a new message being received in a conversation.
- class skpy.event.SkypeEditMessageEvent[source]¶
An event for the update of an existing message in a conversation.
- class skpy.event.SkypeChatUpdateEvent[source]¶
An event triggered by various conversation changes or messages.