Python Technical Overview
From Symbian Developer Community
This article provides an overview of Python on the Symbian platform. It explains the factors that differentiate Python from other programming languages, where you get the files needed to develop on Python on the Symbian platform, and where you can find other key resources.
Contents |
Introduction to Python for S60
Python is a general-purpose object-oriented programming language. It is an easy-to-learn but powerful scripting language whose design philosophy emphasizes productivity and code readability. Many common tasks can be achieved in just a few lines of code by using its extremely comprehensive standard library. This notion is captured in the ‘batteries included’ philosophy, which focuses on the out-of-the-box abilities of the Python distribution.
Python has an open-source, community-based development model that is managed by the Python Software Foundation. Python for S60 is managed as a separate open-source entity, largely bankrolled by Nokia – but a large community effort has grown around it.
Python for S60, better known as PyS60, is Nokia’s port of the Python runtime to the Symbian platform. As such, it uses the same Python core language and idioms. The PyS60 distribution consists of a subset of the standard Python libraries and some newly developed libraries that target mobile-specific APIs, for instance, the sending of SMS, reading contacts or reading orientation from accelerometers. PyS60 serves as a powerful tool for the rapid development of mobile applications and utilities and is also put to good use in the rapid prototyping of sophisticated applications.
PyS60 differs from Flash Lite and Java ME, in that it can be extended using C/C++ by installing DLL extensions. This is an important consideration because you can work around any platform features not directly available in Python by creating a relevant C++ extension and distributing that with your application.
Ease of Use
The main characteristic of Python is its ease of use. Its simple syntax and APIs tend to enable simple tasks to be achieved with clarity and very few lines of code.
For instance, the following code snippets show a full program for obtaining a list of SMS messages in the inbox of an S60 device and for setting the orientation of the application to portrait, respectively.
import inbox
box = inbox.Inbox()
messages = box.sms_messages()
import appuifw
appuifw.app.orientation = ‘portrait’
Its simple and straightforward syntax can be picked up quite easily and its enforcement of indentation helps to improve the readability of code. Anecdotally, many developers are impressed with the productivity improvements achieved with PyS60 as compared with Symbian C++.
Although Python is commonly championed for the rapid prototyping of applications, there is no real restriction on what kind of application can be implemented with it. Indeed, you can build many types of applications using Python, including utilities, games, location-based services and so on (see the sample applications).
As far as efficiency is concerned, Python provides a comprehensive collection of optimized containers, plus the methods to manipulate them. For many tasks, code execution in PyS60 is comparable to the execution of native Symbian C++ code.
Although PyS60 is very rich in APIs, having modules from both the standard Python distribution and S60 mobile-specific APIs, not all Python modules are distributed and the mobile APIs are not as comprehensive as those available to the Symbian C++ program.
For example, Python supports some S60 UI widgets but lacks others, which can sometimes make it difficult to implement applications that look and feel similar to native apps.
To help with this, PyS60 can be enhanced through extensions written in Symbian C++ and is constantly being improved by Nokia (and the PyS60 community). Extensions can be downloaded from the various websites of the developers who contribute them.
PyS60 SDKs and Tools
The PyS60 distribution is made up of two components: the runtime, which provides a virtual machine that manages the execution of Python programs, and the script shell, which is used to run scripts.
Currently there are two versions of PyS60:
- PyS60 2.0.0 (latest stable release) available at garage.maemo.org/projects/pys60 - supports S60 3rd Edition and later releases.
- Recommended for Symbian^1/S60 3nd Edition devices and later
- Based on Python 2.5.1
- PyS60 1.4.5 (stable release) available at sourceforge.net/projects/pys60 - supports S60 2nd Edition and later releases.
- Recommended for S60 2nd Edition devices
- Based on Python 2.2.2
PyS60 versions up to and including 1.4.5 are based on Python 2.2.2, while versions starting from 1.9.0 are based on Python 2.5.1. The Python 3.0 port to S60 is not yet road mapped.
The PyS60 2.0.0 release is recommended for supported devices because it is based on a more modern version of the core, and because it supports many features that are not present on 1.4.5. As suggested in the release announcement, Python for S60 v2.0.0 source will be made available soon in Symbian Foundation, so that users can contribute easily and actively to the growth of PyS60.
The following tables lists the general form of the files available for download at both the above portals and explains what they are for:
| File name | Description |
| PythonForS60_2.0.0_Setup.exe | Installation package for Windows. This installs the Application Packager, the full reference documentation for PyS60 and generic Python in HTML format, and a folder containing the SIS files for the PyS60 runtime (Python_2.0.0.sis), script shell (PythonScriptShell_2.0.0_3_X) and dependencies.
Notes:
|
| PythonForS60_2.0.0.tar.gz | For non-Windows users, an archive PythonForS60_2.0.0.tar.gz is available |
| Python_2.0.0_SDK_3rdEdFPX.zip | The PyS60 SDK
For developing on the S60 emulators Several versions exist, compiled for each supported version of S60 |
| release_notes_2.0.0.txt | PyS60 release notes |
| File name | Description |
| PythonForS60_1_4_5_XEdFPY.sis | The Python runtime
Several versions exist, compiled for each supported version of S60 |
| PythonScriptShell_1_4_5_XEdFPY.sis | The Python script shell
Several versions exist, compiled for each supported version of S60 |
| PythonForS60_1_4_5_doc.pdf | The relevant PyS60 library reference and API docs (applies to all) |
| PythonForS60_1_4_5_SDK_XEdFPY.zip | The PyS60 SDK
For developing on the S60 emulators Several versions exist, compiled for each supported version of S60 |
| PythonScriptShell_1_4_5_3rdEd_unsigned_testrange.sis | The unsigned version of the script shell |
| release_notes_1_4_5.txt | PyS60 release notes |
If you wish to test PyS60 scripts on a Windows PC, you will require a Symbian platform SDK or S60 SDK for C++ application development. The SDK you choose should match the S60 version of the target device. A list of S60 devices is available here. An S60 3rd Edition Feature Pack 2 SDK was used for the purposes of this article.
Support for PyS60
PyS60 extensions and Other Technologies
The following table lists and describes the modules specific to PyS60. One should note that these modules will not be available in standard Python for PC.
| Module | Description |
| appuifw | User interface elements |
| audio | Audio playing and recording |
| calendar | Calendar services |
| camera | Photo and video capturing |
| contacts | Accessing contact information databases |
| e32 | Symbian OS-related utilities |
| e32db | Relational database manipulation |
| glcanvas | UI control for displaying OpenGL ES graphics |
| gles | Python bindings to OpenGL ES |
| globalui | Interface to the S60 global UI notifiers |
| graphics | Image manipulation |
| inbox | Access to inbox, outbox, sent and drafts folders |
| keycapture | Global capturing of key events |
| location | Retrieve location information |
| logs | Generic access to the phone’s log |
| messaging | Messaging services |
| positioning | Retrieve information about the phone’s position using GPS |
| sensor | Access to the device’s physical sensors |
| socket | Bluetooth and other connectivity services |
| sysinfo | Retrieve information about the system |
| telephone | Telephony services |
| topwindow | Creating windows that are shown on top of other applications |
| scriptext | Platform Service API Usage from Python runtime |
Pure Python modules (ones that don’t depend on C/C++ extensions) can be ported across different versions of PyS60. If a module does not rely on a feature or other module that is not available in the target version, the .py or .pyc can be easily copied and used with that version (taking care to ensure that it works with the same version of Python as used by PyS60).
PyS60 extensions can be written in Symbian C++ in order to enhance their functionality. An aggregated list of PyS60 extensions is available at the Forum Nokia Wiki. A tutorial on how to make such extensions is available at wiki.opensource.nokia.com/projects/PyS60_extensions_creation_using_Carbide.
Python can also be combined with Flash Lite with the help of the Flyer framework. The paper Combining Python with Flash Lite and Symbian C++ is an excellent resource.
PyS60 Resources
PyS60 v1.4.5 Reference Documentation:
- PyS60 1.4.5 Library Reference (PyS60-specific APIs and functionality only).
- Python 2.2.2 Reference (generic python)
PyS60 v2.0.0 Reference Documentation
- PythonForS60_2.0.0_Setup.exe (on maemo) contains both generic and PyS60 documentation in HTML format
- PyS60 documentation is also available on maemo garage, in a pdf format (PyS60_2_0_documentation.pdf).
- Python 2.5.1 Reference (generic python)
The foremost source of information about PyS60 is the book Mobile Python - Rapid prototyping of applications on the mobile platform by Jürgen Scheible and Ville Tuulos. Symbian Press provides a sample introductory chapter online (see book link above) and a website with source code for all the examples in the book: www.mobilenin.com/mobilepythonbook/examples.html
It is possible to file bug reports or submit feature requests for upcoming PyS60 releases using the PyS60 project tracker garage.maemo.org/tracker/?group_id=854
There are also numerous websites that can prove to be invaluable when learning PyS60. We recommend the following:
- forum.nokia.com, with its Python sections of the wiki and discussion boards
- mobilenin.com
- croozeus.com
- Home to PyS60 Developers
Sample Applications
Numerous outstanding PyS60 applications and games demonstrate what can be done using this powerful language. Some of them are featured below. A concrete list of more PyS60 applications can be found at Forum Nokia Wiki.
- PyCalc – a utility that demonstrates how to link several scripts and make use of other resources, such as images
- ShakerRacer – allows you to control a toy racing car with your phone through Bluetooth
- Location Scheduler – trigger alarms or reminders according to location
- Tracker – an advanced application that makes use of GPS and maps
- Unity – an excellent example of the potential PyS60 has for game development
- Sensor Sample - demonstrates how to use the built-in Sensor API in Python applications
- Scribble - Paint like application demonstating use of touch support (compatible with PyS60 1.9.5 and an S60 5th Edition device/SDK)
- GTranslate - Python application that uses Google translator API to translate English to other languages
Comments
Sign in to comment…







