Python Power: Growing Respect for an Open Source Integration Tool

Open-source software now plays a crucial role in the majority of large information technology (IT) organizations. It’s not the role you’d think, though, from popular descriptions of Open Source. .

When leaders such as Hostway Corp. and Journyx, Inc. talk about their use of Python, they’re not talking about the virtues of low licensing cost, or waging an ideological battle against Microsoft. Python actually provides them a strategic advantage by providing them a low-cost, easy-to-deploy tool for helping enterprise software systems to talk with one another. In fact, rather than thumbing their nose at Microsoft, these companies use Python to maximize the value of their Windows applications.

Here is the short list of advantages IT managers — and even their non-technical executive bosses see from Open Source Python:

  • the ability to integrate proprietary systems;
  • high productivity; and
  • enhanced security

Open Source Re-engineering the Enterprise
In these regards, enterprise-class open-source software has more in common with old-style mainframe software, than it does with the hobbyist personal-computer retail software of the ’90s.

During this last decade, many companies “re-engineered” themselves several expensive rounds of “re-engineering” themselves to fit the enterprise resource planning (ERP), customer relations management (CRM), and other strategic software to which they’d committed. Despite these large investments–and sometimes because of them–automation gaps still riddle these companies’ processes.

To file an expense report, secretaries still print out computer forms, copy data by hand, and re-enter results. Technicians transfer codes from manufacturing to inventory
systems, often introducing typographical errors along the way.

Python is a highly-productive programming language with a proven record of bridging such gaps. That’s what it does for Journyx, a software vendor and consultancy which specializes in time-keeping applications. Much of the value of Journyx’s offerings lies in
their ability to integrate with “foreign” departmental software, including accounting, ERP, and personnel programs. Journyx founder and CEO Curt Finch emphasizes Journyx’s focus on adding value to the “trusted IBM products” and other programs his customers already
use.

Manual effort-reporting and time-keeping systems invariably operate with errors around 5%, and sometimes as high as 10%. Well-designed integration with flexible tools like Python brings such errors under control.

What makes Python so good for integration? Finch and other believers in Python note several characteristics:

1. Python is portable: It works on and with all the platforms likely to be found in the
enterprise.

2. Python is easy to learn. Python makes for an excellent first language. This is a particular advantage for developers who spend most of their time with specialized products or technologies, and only occasionally turn to Python to glue together pieces
that would otherwise be compatible.

3. Python is high-quality: While it’s matured for over a decade now, its developmental philosophy is so conservative it only recently reached version 2.2.

4. Python’s design emphasizes clarity and teamwork. Python was designed with integration problem-solving in mind. From the beginning, the code enables both developers and systems to co=operate with one another.

Python Fit for Mission-Critical Duty 
For all these benefits, there is one other benefit from Python — compared with many other Open Source technologies — that stands apart for Finch and other execs. Python is up to the rigors of mission-critical operation.

For top-rated international hosting provider Hostway, 24-hour-a-day reliability is essential. In fulfilling that requirement, Hostway Director of Research and Development Jason Abate says, “We’ve been extremely happy with how Python plays with our proprietary software
infrastructure. We’ve found the common benefits of Python (clean syntax, complete library, etc.) to be a perfect match for our development.,” Abate told OET.

“We’re able to both quickly glue together many disparate systems as well as construct a solid, reliable software infrastructure. We’ve built a custom middleware layer that allows us to cleanly plug in third party applications, libraries and tools into our system and allow them to be cleanly accessed by any other piece of the system. This lets us transparently scale our offerings and take advantage of whatever technology is best suited to our immediate needs.”

Python for Web Services — Case in Point
To give developers a flavor for just how useful Python can be in prepping data for integration or to be offered as part of a web service, John Bair offers a generic script using expat to convert xml into objects. Bair notes his sample code set is borrowed from wxPython XML tree demo with modifications. (This is just one example of Python code available at the Python Cookbook, a joint project of ActiveState and O’Reilly & Associates.)

 



import string

from xml.parsers import expat


class Element:

    'A parsed XML element'

    def __init__(self,name,attributes):

        'Element constructor'

        # The element's tag name

        self.name = name

        # The element's attribute dictionary

        self.attributes = attributes

        # The element's cdata

        self.cdata = ''

        # The element's child element list (sequence)

        self.children = []

        

    def AddChild(self,element):

        'Add a reference to a child element'

        self.children.append(element)

        

    def getAttribute(self,key):

        'Get an attribute value'

        return self.attributes.get(key)

    

    def getData(self):

        'Get the cdata'

        return self.cdata

        

    def getElements(self,name=''):

        'Get a list of child elements'

        #If no tag name is specified, return the all children

        if not name:

            return self.children

        else:

            # else return only those children with a matching tag name

            elements = []

            for element in self.children:

                if element.name == name:

                    elements.append(element)

            return elements


class Xml2Obj:

    'XML to Object'

    def __init__(self):

        self.root = None

        self.nodeStack = []

        

    def StartElement(self,name,attributes):

        'SAX start element even handler'

        # Instantiate an Element object

        element = Element(name.encode(),attributes)

        

        # Push element onto the stack and make it a child of parent

        if len(self.nodeStack) > 0:

            parent = self.nodeStack[-1]

            parent.AddChild(element)

        else:

            self.root = element

        self.nodeStack.append(element)

        

    def EndElement(self,name):

        'SAX end element event handler'

        self.nodeStack = self.nodeStack[:-1]


    def CharacterData(self,data):

        'SAX character data event handler'

        if string.strip(data):

            data = data.encode()

            element = self.nodeStack[-1]

            element.cdata += data

            return


    def Parse(self,filename):

        # Create a SAX parser

        Parser = expat.ParserCreate()


        # SAX event handlers

        Parser.StartElementHandler = self.StartElement

        Parser.EndElementHandler = self.EndElement

        Parser.CharacterDataHandler = self.CharacterData


        # Parse the XML File

        ParserStatus = Parser.Parse(open(filename,'r').read(), 1)

        

        return self.root

    

parser = Xml2Obj()

element = parser.Parse('sample.xml')


Cameron Laird is a vice president with Phaseit, Inc. http://www.phaseit.net/ where he specializes in highly-reliable, lightweight
solutions to integration challenges. You can contact Cameron at claird@phaseit.net 

More Python Resources
You can try out Python yourself with just a couple of hours of free time. Several excellent books and tutorials cover Python, in both on-paper and on-line versions. It’s quick work to download and install a no-charge copy of the Python processor, and you can begin to write your own programs soon after. Check out the references below

  • The Python.org home page offers a variety of recent Python downloadstutorials,documentation, and backgrounders on using Python with other languages and platforms.
  • A very through Python tutorial, co-authored by Python’s creator Guido van Rossum. Chapters address the Python Interpreter, Control Flow Tools, Data Structures, Modules, and Handling Exceptions.
  • To get “down to business” with Python — using it in your enterprise, the Python Business Forum offers code and Case Studies. Registered in Sweden last May, the PBF features Use Studies from Google, Industrial Light and Magic, Yahoo and Inktomi.
  • PythonBooks offers a wide range of Python books, designed for every experience level — from beginner to advanced. Publishers include O’Reilly, Prentice-Hall, Addison-Wesley, Manning and others.
  • A useful discussion on how to use Python to test an application program’s ability to conduct inter-process communications is presented on one of the Python.org mailing lists at http://mail.python.org/pipermail/tutor/1999-September/000561.html.