The Python Web Services Developer: Part 1

Working with web services, using the tools and facilities that come with Python, is outlined in this first of three part series by Mike and Uche.

Python’s motto has always been “batteries included,” referring to the large array of standard libraries and facilities that come with the language installation. This article presents an overview and survey of tools and facilities available for Web services development in Python. This includes built-in Python features and third-party open-source tools.{mospagebreak title=Article&toc=1}

Welcome to the “Web services for the Python developer” column. But wait, don’t hesitate when we say “for Python developers.” This column is not purely for the Python Guru, or even the Python journeyman. As much as possible, we will try to accommodate beginners and those who are merely curious.

We intend to direct our readers to high-quality resources for the relevant background information necessary for each topic in this series. It is our hope, that in this way Python developers of all levels will be able to gain something from this column. In many cases, however, Python’s legendary readability (it has sometimes been called executable pseudocode) means that most readers will be able to follow the code with little trouble.

And there will be much code. This column will be hands-on and very practical. In most installments we shall actually be developing a useful Web Service, which you should be able to employ with little effort for your own purposes. So get out your snake-charming pipes and get ready to construct Web services more productively than you might have imagined. In this inaugural article, we shall explore the many features and resources that make Python such a great programming language for developing Web services.

A Bit of Background

Since you’re in the Web services zone, there’s a decent chance you know what a Web Service is — if not, see the links in the Resources section for some good reading on the general topic. But in order to place Python within the world of Web services, we ask that you indulge us while we step back and build a little perspective.

The Web has developed at a remarkable pace since it’s birth barely a decade ago. First came the original collection of interconnected articles and links. Then came CGI and with it the first glimpse of the Web’s potential to revolutionize software development: CGI provided narrow, highly-specialized functions for presenting dynamic content. From these roots have come Web services.

One way to think about what sets Web services apart from other dynamic Web content is to think of application objects versus components. Objects are highly specialized bundles of code and data that are designed to drop into a sharply defined slot in an application. Components are also objects, but they are usually more generally applicable and highly reusable in a variety of applications and environments. Normally, they are associated with formal protocols (for example, CORBA, DCOM, and EJB) for communicating with other code, describing their interface to other code, and discovering and managing them at run time.

Similarly, Web services are, at the most basic level, simply a subclass of dynamic Web content, differentiated by their generality, reusability, and the formal protocols (SOAP, UDDI, WebDAV) that standardize their communication, interface definition, management, and so on.

So Where Does Python Come In?

Python has always had extensive support for basic Internet protocols, which along with its readability and ease of maintenance has made it a strong foundation for dynamic programming. Here we list some of the core facilities of Python that are useful for Web services development. Everything listed comes with Python and requires no additional download or installation.

  • HTTP: The core library includes full-blown HTTP 1.1 server implementations, including file and CGI servers. These are very easy to customize for your own purposes and they already help automate Web serving tasks for you. Naturally, there are also tools for making HTTP requests, including the low-level httplib which gives you control over all aspects of the HTTP request, and the quick and dirty urllib which simply takes a URL and fetches the data from the appropriate location. Note that Python also provides SSL support, which allows secure Web sites through HTTPs.
  • URL parsing and construction: There are modules for breaking down and putting together URLs from more natural Python data structures. These make it easy for your Web service to handle URLs with request parameters, fragments, and so on.
  • CGI: There is a full suite of tools for interpreting CGI requests and making it easy to write effective CGI handlers.
  • HTML (and SGML): Python comes with modules for parsing HTML and its parent language SGML.
  • XML: Python has had a strong array of XML support throughout XML’s brief history. A couple of XML parsers, DOM, and SAX libraries come in the standard library.
  • FTP, SMTP, NNTP, POP, IMAP, and so on: The library is rich with client modules for these other important Internet protocols. Each one provides a very fine level of control over the particulars of the session as well as an impressive toolkit for parsing the data formats into more Pythonic structures. These come in very handy for gluing Web services to other Internet applications; for instance, they provide event notifications via e-mail.
  • Low-level sockets: Just in case you really want to get down and dirty with network programming, you can break out of the convenience of the above-mentioned modules and twiddle bits and bytes across the network any way you can imagine. The Python library comes with client and server socket programming modules.
  • Browser controls: Python comes with a neat module, webbrowser, for launching and controlling a wide variety of Web browsers (including Netscape, Internet Explorer and Konqueror). This is a useful tool in for bridging traditional components to a Web service in an Intranet or similar environment.

With this panoply of facilities, Python has the basics of Web services well covered. However, we have mentioned the higher-level considerations that make Web services special. These features are generally the preserve of third-party additions and applications for Python.

A Brief Survey of Third-Party Python Tools

Beyond the “batteries included” approach in the Python standard library, there is a rich vein of third-party add-ons for Web service development (and almost any other purpose you can dream up). See the Resources section for links to sites that will assist you in locating tools for use with Python. All software discussed here is open source.

XML is a very popular data format for Web service purposes. Its high structure and extensibility, broad support, and variety of related standards make it popular for encoding requests, responses, and communications between sub-components of the service. We have already touched on Python’s built-in XML facilities. There are also many third-party XML tools. The Python XML SIG develops the PyXML package which adds a variety of parsers, DOM and SAX tools, data-marshalling tools for WDDX and XML-RPC, and miscellaneous XML processing tools. There is also Sean McGrath’s Pyxie for an original approach to XML processing.

An additional array of XML tools is provided in 4Suite (co-developed by the authors), which builds on PyXML and adds many XML-related facilities including DOM (transient and persistent), XPath, XPointer, XSLT, XLink, RDF, and XInclude. With these facilities alone, many aspects of a Web service can be developed with little custom code required. In particular, RDF is the most promising technology for describing relationships and data that must be indexed for Web services. Python has RDF support both in 4Suite and in James Tauber’s Redfoot framework.

SOAP is certainly the darling protocol of Web services. SOAP is a protocol for sending messages to remote systems using strictly-specified XML embedded in HTML, SMTP, or other lower-level protocols. Pythonware’s soaplib provides basic SOAP and XML-RPC support for Python. There are currently some interoperability problems between soaplib and other popular SOAP implementations, but a new release is imminent that promises improved interoperability and broader SOAP support. There is also some rougher and older SOAP code available from Ken MacLeod’s Scarab project.

Fourthought’s 4Suite Server (also co-developed by the authors) is an XML data server based on 4Suite that provides out-of-the box support for storing, managing, transmitting, and processing XML. It supports communications using CORBA, HTTP, and very basic SOAP, and will soon add more protocols such as WebDAV and SMTP.

Digital Creations develops Zope, a popular Python-based application server; Zope provides general object services, template-based HTML output, and WebDAV. XML support is in development.

Chuck Esterbrook’s Webware is a suite of tools for developing Web-based applications in Python. It is similar to Java servlets, JSP, and similar facilities.

Finally, since most users still access the Web using HTML-only Web browsers, being able to render HTML is an important part of most Web services. DOM has some facilities for building HTML documents and 4Suite can output HTML from DOM or XSLT. If a template-based approach is preferred there is Robin Friedrich’s very mature HTMLgen module.

Buzzword Breakdown

Here are brief definitions for some of the jargon used in the article.

Common Object Request Broker Architecture (CORBA): The Object Management Group’s standard for object-oriented components.

Distributed Component Object Model (DCOM): Microsoft’s standard for object-oriented components.

Enterprise JavaBeans (EJB): A standard for Java-based component development.

Simple Object Access protocol (SOAP): A specification for encoding messages to remote objects in XML using protocols such as HTTP and SMTP.

Universal Description, Discovery and Integration (UDDI): A standard for directories of Web-based services.

Web Document Authoring and Versioning (WebDAV): A standard for modifying and managing documents on remote Web servers.

Document Object Model (DOM): A standard for object-oriented access to XML and HTML documents.

Simple API for XML (SAX): A specification for accessing XML documents using an event-based model.

Secure Sockets Layer (SSL): A standard for encrypted communication over the Internet and similar networks

Web Distributed Data Exchange (WDDX): A schema for exchanging program data as highly structured XML.

{mospagebreak title=Next Stop: Code&toc=1}

Hopefully these resources get you started. Practice if you can because from now on it will be mostly real-world code solving real-world problems. In the next few articles in this column, we shall develop a practical Web service: a software library service. You shall see how to put to work many of the tools we have introduced in this article.


  • Participate in the discussion forum on this article.
  • Get an overview of the purpose of this series by reading the second installment.
  • Read the third installment of this series.
  • Our fellow Web services columnist Graham Glass has an excellent overview of Web services in his article “The Web services (r)evolution, Part 1.”
  • Python is a popular general purpose, application-development language famed for its readability, sensible design, and comprehensive standard library.
  • There are many online Python introductions and tutorials. IBM developerWorks has published Python 101 by Evelyn Mitchell. There is also Python Programming for Beginners on Linux Journal. The Python documentation comes with a tutorial. Josh Cogliati’s tutorial is also a very gentle introduction.
  • The Vaults of Parnassus is an on-line database of openly available software for Python.
  • The faqts Python knowledgebase is a good place to get answers to all sorts of questions about Python.
  • In some of David Mertz’s developerWorks columns he covers XML processing in Python. See
  • The Python XML SIG develops the PyXML package, which beefs up Python’s native XML support.
  • Sean McGrath’s Pyxie provides XML parsing and processing tools, generally using a line-oriented approach that is quite developer friendly. Mr. McGrath is also author of the book XML Processing with Python, published by Prentice-Hall, February 2000 (ISBN: 0130211192).
  • 4Suite and 4Suite Server, co-developed by the authors, implement many XML-related technologies.
  • soaplib is Pythonware’s SOAP implementation. Windows users can ease into SOAP by using Andrew Dalke’s Lye, a COM to SOAP converter. Another SOAP implementation is Ken MacLeod’s Scarab project.
  • James Tauber’s Redfoot project is a Python-based framework for RDF servers.
  • Robin Friedrich’s HTMLGen provides a template-based approach to rendering HTML documents.
  • Zope, by Digital Creations, is a general purpose application server for Python, and provides a variety of Web services features.
  • Chuck Esterbrook’s Webware provides a set of Web development tools that will be familiar to users of ASP, Java servlets, JSP and the like.

This article Originally appeared at

[gp-comments width="770" linklove="off" ]

chat sex hikayeleri Ensest hikaye