Automating Skype with Skype4Py: Useful Scripts and Examples
Skype4Py is a Python wrapper for the Skype Desktop API (Windows/Mac/Linux) that lets you control a Skype client programmatically: send/receive messages, manage calls, access contact and chat info, and respond to events. Note that Skype4Py interfaces with the local Skype application, so the Skype client must be installed and running.
Setup
- Install Skype and sign in.
- Install Skype4Py (for older Python versions):
- pip install Skype4Py
- Create a Skype client and attach to the running Skype instance:
python
import Skype4Py skype = Skype4Py.Skype() skype.Attach()
Common usage patterns
- Event-driven automation: register event handlers to react to incoming messages, calls, or status changes.
- Scripting actions: send messages, initiate calls, get contact lists, change status.
- Periodic tasks: poll chats or contacts if needed (less preferred to events).
Useful example scripts
- Auto-reply bot (simple)
python
import Skype4Py skype = Skype4Py.Skype() def on_message_status(message, status): if status == ‘RECEIVED’ and message.Type == ’S’: # S = chat message if ‘hello’ in message.Body.lower(): skype.SendMessage(message.Chat.Name, “Hi! This is an automated reply.”) skype.OnMessageStatus = on_messagestatus skype.Attach() while True: pass
- Message logger (write incoming messages to a file)
python
import Skype4Py, datetime skype = Skype4Py.Skype() def on_message_status(message, status): if status == ‘RECEIVED’: with open(‘skype_messages.log’, ‘a’, encoding=‘utf-8’) as f: f.write(f”{datetime.datetime.utcnow().isoformat()} | {message.FromHandle} | {message.Body} “) skype.OnMessageStatus = on_message_status skype.Attach() while True: pass
- Send scheduled message “`python import Skype4Py, time, datetime
skype = Skype4Py.Skype() skype.Attach()
def send_at(chat_name, text, when): while datetime.datetime.utcnow() < when: time.sleep(5) skype.SendMessage(chat_name, text)
Example: send in 1 minute
send_at(‘echo123’, ‘
Leave a Reply
You must be logged in to post a comment.