Manage Learn to apply best practices and optimize your operations.

Notable Python language update on view

Google's interest in Python is just one reason this language continues to gain attention. If you are looking for a scripting language to do some rapid prototyping of SOA style applications with, you will probably find the functions you want in Python 3.0.

I last took a look at Python (in version 2.4) for web service clients several years ago. As a scripting language, Python is popular for utility quick projects and comes pre-installed on many systems. Python scripts, identified by the .py file type, turn up in many places. Python is available for a huge variety of platforms. The basic language is completely open source but the license permits the development of custom commercial versions. Sun is putting a major effort into the development of Jython for running Python programs on the Java Virtual machine with access to Java libraries. Many developers comment that their Python projects get to working code surprisingly quickly.

A major effort by the Python developer group has created Python 3.0, released in late 2008. Major changes to the handling of strings (now Unicode) and cleanup of obsolete methods mean that backwards compatibility to Python 2 programs has been lost. As a parallel development, Python version 2.6 has also been released at the same time with the intent of creating an easy migration path for Python developers to eventual use of version 3.0. Google's App Engine, which lets you run your web applications on Google hardware, currently supports Python version 2.5 but is being updated to 3.0. Since many of the Python developer community, including Guido van Rossum, the original author of Python, work for Google, this update should occur rapidly.

Support for Networking

The Python standard library comes with extensive support for networking, from socket level to HTTP and email protocols. The socket tools support both IPv4 and IPv6 addressing. The low level protocols UDP and TCP are supported and the standard library contains support for creating your own custom servers.

A large variety of Python based web application frameworks have sprung up, but the Python community appears to have settled on WSGI, the Web Server Gateway Interface, as a unifying specification. Commercial and open source frameworks supporting WSGI include the Google App Engine. Generally these frameworks have not been completely updated to Python 3.

XML Support

Python 3 supports the W3C DOM model for XML at the "level 2" recommendation. There is also a "lightweight" DOM implementation corresponding to the W3C level 1 (circa 1998) without the added complexity of namespace support. A rather clever "pulldom" API provides for creating partial DOM structures during SAX parsing, especially handy when working with very large XML documents. Primitive parsing functions are not written in Python but use the "expat" parser written in C for speed. Expat is a non-validating parser. Limited XPath support exists but is not well documented.

The Python community does not appear to be too enthusiastic about creating support for SOAP, WSDL and WS-* standards, although some projects exist. REST style web services would appear to be a better fit for Python given Python's emphasis on simplicity.

Python and JSON

JSON, short for JavaScript Object Notation, support in the Python standard library is new and appears in both version 2.6 and version 3.0. JSON has become many developer's technology of choice for communicating data to Rich Internet Applications (RIA). JSON is compact and easily accessed in browsers with code similar to that used to evaluate XMLHttpRequest results but cannot communicate complex hierarchies of data like XML can.

The JSON library lets you serialize the data content of a Python object, for example in response to a browser request. Furthermore, you can populate Python data structures from JSON text. The Google App Engine provides extensive support for creating and using JSON formatted data.

Python and XML-RPC

XML-RPC is the simple protocol for executing remote procedure calls using XML encoded messages. This is, of course, the idea which accumulated lots of extra complexity and evolved into SOAP. XML-RPC implementations are available for many languages in addition to Python, including Java and .NET.

Example code in the version 3 distribution shows a huge number of alternative ways to create a server to handle XML-RPC style requests to execute Python methods and return properly formatted XML. Your program does not have to know a thing about XML, the Python toolkit handles all of the interpretation of a request in terms of Python methods and variables, and formats the response.

An exceptionally cool feature provides for creating HTML documentation of a Python XML-RPC method in response to a simple HTML GET directed to the service URL. To refresh your memory as to how simple XML-RPC is in comparison to SOAP, I ran the example XML-RPC server and client programs included in the Python 3.0 standard library and captured the request and response. Here is the request generated by only two lines of code:

Host: localhost:8080
Accept-Encoding: identity
Content-Length: 187
Content-Type: text/xml
User-Agent: (by

<?xml version='1.0'?>

On the server side, a couple of lines created a server instance and registered the "pow" method. The server response was:

HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.0
Date: Thu, 29 Jan 2009 20:29:17 GMT
Content-type: text/xml
Content-length: 122

<?xml version='1.0'?>


If you already have a body of Python to support, the switch from earlier versions to Python 3 will require significant effort but this will pay off due to the support of Unicode. If you need a language to develop applications to support Unicode and run on a wide variety of operating system platforms, Python is an obvious choice. If you are looking for a scripting language to do some rapid prototyping of SOA style applications with, you will probably find the functions you want in Python 3.0. If you need WS-* support for SOAP/WSDL, you should probably look elsewhere.


The official home of the Python Programming Language

A summary of the new features in Python 3.

Python on the Google App Engine.

This site gives the syntax of JSON and lists languages and toolkits supporting it.

My article on the XML-RPC beginning of web services.

This Wikipedia article lists many XML-RPC implementations.

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.