Introduction to IronPython & Silverlight

Python in Your Browser

That cunning snake


Silverlight is a browser plugin from Microsoft. Through Silverlight it is possible to create dynamic applications and natively script the browser with Python.

In this series of articles we will look at what it is possible to achieve with Silverlight, and how to get started with dynamic applications. This includes the following topics:

  • Create dynamic applications
  • Using the Silverlight APIs
  • Including consuming XAML and create controls
  • Access the browser DOM
  • Calling between Javascript and Silverlight code
  • Embed IronPython in a C# Silverlight application
  • Compile C# for Silverlight without Visual Studio installed

The examples used throughout these articles are online and available for download.

For a more thorough introduction to creating applications with IronPython and Silverlight, read chapter 13 of IronPython in Action. This takes you through more of the APIs, including creating a full application: a Twitter client that runs in the browser. The first chapter of IronPython in Action is available online free, and gives a great introduction to both Python and IronPython.


IronPython is an implementation of the popular dynamic programming language Python. Python is a general purpose programming language used for everything from desktop applications, running YouTube, games, managing Imageworks animation pipeline, automated hard drive testing for Seagate - and much more.

IronPython runs on the .NET framework and Mono. This allows Python programmers to take advantage of the extensive framework libraries and powerful runtime of .NET, and allows .NET programmers to take advantage of Python!

IronPython was originally created by Jim Hugunin, and is now developed by a team of programmers (which sometimes includes Jim!) at Microsoft. IronPython is a Python compiler, compiling Python code to in memory assemblies.

IronPython 2 targets Python 2.5 and is built on the DLR (Dynamic Language Runtime).


Silverlight is Microsoft's entry into the rich internet application framework race.

  • A cross-platform cross-browser plugin
  • Intended for games and Rich Internet Application
  • Silverlight code runs in the browser
  • Streaming media and video
  • Includes the 'CoreCLR'
  • Through the DLR, runs IronPython

Silverlight is a sandboxed browser plugin for creating rich client-side web applications. It runs on Windows and Mac OSX, supporting Firefox, IE and Safari (with support for more browsers on the way). Nokia S60 and Windows Mobile support have also been announced.

There is a Mono version called Moonlight, which runs on Linux (supporting Firefox). This is officially backed by Microsoft who are making the media codecs, the test suite and the full specification available to the Mono team. Initially it will target Firefox on Linux, but eventually will run on multiple browsers everywhere that Mono runs.

Version 1 of Silverlight focussed on media streaming and is programmed with Javascript. Version 2 ships with a cut down version of the CLR (the core of the .NET framework). It can be programmed with C# or any of the DLR languages which includes IronPython.

What Does Silverlight Offer

  • A video player!
  • A user interface based on Windows Presentation Foundation
  • 'Deep zoom' and adaptive streaming
  • Client side storage (1MB per app but you can request more)
  • A rich set of APIs (JSON, XML, threading, sockets)
  • Access to the browser DOM and Javascript
  • Performance (IronPython run in Silverlight outperforms traditional Javascript by a couple of orders of magnitude)
  • Python!!

It isn't just Python that you can program Silverlight with. The dynamic languages currently available (from Microsoft) for Silverlight are IronPython, IronRuby and managed JScript. Why managed JScript? Managed Javascript is ECMAScript compliant (ECMAScript 3.0) - so code written AJAX style with traditional Javascript can be ported over to run in Silverlight, and run much faster. Really well integrated with the rest of the platform.

These languages can also interoperate with the traditional .NET languages. They can use classes created from C# /VB code without wrappers. To the dynamic languages they are natural objects just as much as ones they have created themselves.

There are several ways that dynamic applications can use Silverlight:

  • The Silverlight control is the main user interface on the web page
  • The Silverlight control occupies only part of the page (like flash) and optionally interacts with Javascript and HTML in the page. You can even embed several controls in a page.
  • The Silverlight control is completely hidden and acts as a calculation engine that runs in the background
  • A fullscreen mode

One major difference between Silverlight and Adobe Flex/AIR is that there is currently no way to use Silverlight to create applications that are separate from the browser (well the Mono guys have done this with Moonlight).

Silverlight separates presentation from code (design from development), through XAML. This is an XML markup for creating user interfaces, including theming interfaces and defining animations. This is intended to be created by tools like Expression Blend (currently in free beta). There is also a version for Mono called 'Lunar Eclipse' under development. We will be looking at how to create user interfaces, using the fancy new controls for Silverlight 2, either by working with XAML from IronPython or directly from code. We'll also explore interacting with the browser DOM and (normal) Javascript.

First we'll look at the structure of an IronPython & Silverlight application.

For buying techie books, science fiction, computer hardware or the latest gadgets: visit The Voidspace Amazon Store.

Hosted by Webfaction

Return to Top

Page rendered with rest2web the Site Builder

Last edited Sat Aug 14 14:30:21 2010.