Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Interacting with Skype from Python using Skype4P...

http://query7.com/interacting-with-skype-from-pyth...

Query7
Home Request A Tutorial About Contact

Interacting with Skype from Python using Skype4Py


Posted on January 3, 2011 Skype4Py is a Python module that allows developers to programatically interact with the Skype client running on their computer. In this tutorial we will look at and use the Skype4Py module to create simple but useful scripts.

Installation
Skype4Py is a normal Python module and is listed in the Python package index (Pypi). To install it with setuptools enter the following in a command prompt.
easy_install Skype4Py

To install it with pip enter the following in a command prompt.


pip install Skype4Py

Getting Started
Skype4Py interacts with the Skype client running on your desktop, it doesnt talk directly to the Skype servers. For any of the scripts we cover in this tutorial to work the Skype application must be running and you need to be logged in. You can either start Skype yourself or use the following snippet to start it using Skype4Py.
s = Skype4Py.Skype() if not s.Client.IsRunning: s.Client.Start()

Before we can interact with the Skype client from Skype2Py, we need to connect Skype4Py to the instance of Skype running on your desktop. This is done using the Attach method.
1 de 5 28-02-2012 14:07

Interacting with Skype from Python using Skype4P...


import Skype4Py s = Skype4Py.Skype() s.Attach()

http://query7.com/interacting-with-skype-from-pyth...

After executing this you need to check the Skype client on your desktop. A notication similar to the one below will appear. This ensures that no virus or 3rd party program can use your Skype account without your knowledge. Click Allow access.

User Information
Skype4Py provides a User class which represents a users Skype account. We can access information such as the users full name, their Skype status and when they were last logged into Skype. To get the person who is currently logged into the Skype clients information we need to use the CurrentUser class.
import Skype4Py s = Skype4Py.Skype() s.Attach() print 'Full Name: %s' % s.CurrentUser.FullName print 'Skype Status: %s' % s.CurrentUser.OnlineStatus print 'Country: %s' % s.CurrentUser.Country

To access information about the current Skype users friends, we need to use the Friends class. The snippet below iterates over all of the current Skype users friends and prints some information about them.
import Skype4Py s = Skype4Py.Skype() s.Attach() for f in s.Friends: print 'Full Name: %s' % f.FullName print 'Skype Status: %s' % f.OnlineStatus print 'Country: %s' % f.Country

Sending SMS Messages


Skype4Py can also be used to send SMS messages. Only Skype users who have credit in their Skype account can send SMS. Be sure to check local SMS rates on the Skype website before using and never put this code in a loop without

2 de 5

28-02-2012 14:07

Interacting with Skype from Python using Skype4P...

http://query7.com/interacting-with-skype-from-pyth...

double checking it rst. Make sure you include your countrys international prex at the beginning of the number variable. After using this code my phone received the SMS 20 seconds later (NZ carrier).
import Skype4Py s = Skype4Py.Skype() s.Attach() message = 'Hello SMS from Query7' number = '+641234567890' m = s.CreateSms(Skype4Py.smsMessageTypeOutgoing, number) m.Body = message m.Send()

What Else Can Skype4Py Do?


Download and play voice mail messages Transfer files between Skype clients Interact with Skype chat messages

Leave a Reply
You must be logged in to post a comment.

Search Keywords

Search

Subscribe to feeds Sourcebits

Web Design | Web Development

Categories
ActionScript (2)

3 de 5

28-02-2012 14:07

Interacting with Skype from Python using Skype4P...

http://query7.com/interacting-with-skype-from-pyth...

ajax (3) Android (4) Best Practices (7) book review (1) code (4) Code Igniter (3) Design (7) django (4) dropbox (2) fedora (3) Flash (2) Flex (6) Git (2) JavaScript (9) jQuery (21) kohana (4) linux (9) Mail (1) mongodb (1) nodejs (1) php (32) php-gtk (2) Programming (16) Python (9) Ruby on Rails (2) security (2) This Week in Web (25) Titanium Mobile (4) Tutorials (23) twig (2) videotutorial (4) Web 2.0 (5) Web Development (72) wordpress (1) Zend (3)

Recent Posts
This Week in Web PHP Needs X, Python IDEs, Firefox5, jQuery Mobile, Python Games This Week in Web SMF2, ZF2, Python Lamdas, Future of JS, Titanium 1.7 This Week in Web -Django Hosting, Podcasts, Git Tutorials, Python Apps
4 de 5 28-02-2012 14:07

Interacting with Skype from Python using Skype4P...

http://query7.com/interacting-with-skype-from-pyth...

with Titanium This Week in Web jQuery API, Python Video Archive, Symfony2 Beta, Heatmap.js This Week In Web Python, NodeJS CMS, Google APIs, XDebug

Recent Comments
Tijmen on Titanium Mobile Android Development: First Application logan on Titanium Mobile Android Development: First Application Tijmen on Titanium Mobile Android Development: First Application Tyrael on Why You Should Be Using a PHP Framework nicoSWD on Why You Should Be Using a PHP Framework

Blogroll
Sourcebits Blog Spoonjuice Blog Android Development iPhone Development Web Development 2011 Query7 - Powered by Wordpress. Web Development by

5 de 5

28-02-2012 14:07

You might also like