Webizing Python


Python* objects need to become first class objects on the Web, and the way to do that is to give them URIs. Everything of importance in Python needs a URI: modules, functions, variables, etc. Just as it's wrong to break public URIs, it's wrong to break public API*s, and giving them formal identifiers helps make peristence contracts clearer.

Conversely, URIs need to become first-class objects in Python. Python needs a standards-compliant URI type or class. A type would be especially cool, allowing one to easily refer to a URI like so:

DanC = <http://www.w3.org/People/Connolly/#DanC>

Web Access

Once we've added URIs to Python we can make good use of them. The first and most obvious is to use the Web for grabbing and updating modules. In our theoretical WebPython, you can simply:

import <http://www.w3.org/2000/10/swap/cwm>

Python will (securely) grab the module (if it doesn't already have it) and cache it for faster future access. Of course, it should occasionally check for upgrades as well.

Of course this leads into some problems. One of the first ones that comes to mind is that import * simply doesn't work in a Web system. When the contents of modules can dynamically change, doing an import * can cause serious naming collisions.

Webized Objects

Python objects need to be webized too, and a great way to do this would be to use an RDF-based system. Python could have an rdfPickle which pickled objects in a webby way. (May want to s/RDF/XML/...) The Web has taken great strides to deal with the document versioning problem and mixing namespaces. A lot of this work can be applied to Python.

Remote Objects

Python is lacking a way to deal with remote objects over the Web. However, to make Python objects fit into the Web's distributed object system, you need to add a little bit of metadata. REST, the architectural foundation underlying HTTP* shows just how important it is to generalize simple actions like GET, POST and PUT. By adding metadata like this to functions (do they have side effects or not?) Python objects can become first-class Web citizens. Zope* is an interesting example of one way to export Python objects to the Web.

Eventually, Python should a first-class distributed computing language. In this area there's a lot to learn from the E folks. There are so many possibilities when programming looks beyond just the local machine and stretches to become a powerful network like the Web. You can see the excitement behind XML-RPC* and SOAP* with so-called Web services* and the growing momentum behind the Semantic Web. It'd be great to see Python take bold steps into this new world.

See Also

URI API design thread on W3C's URI email list.

Python urlparse bug

TimBL has also mentioned that a urlsplit (the opposite of urljoin) function would be nice.

Part of LogicError. Powered by Blogspace, an Aaron Swartz project. Email the webmaster with problems.