[Twisted-Python] To twisted.web beginners: don't use RPYs

Itamar Shtull-Trauring itamar at itamarst.org
Wed Jun 18 18:32:20 EDT 2003

This seems to be a common misunderstanding, so let me emphasise this.

   RPYs are *glue* for integration with static filesystem content. They
   should never contain large amounts of code.

In general, development for twisted.web should be done by a tree of
resources in memory, hooked up manually to a site object in your code.
RPYs are intended for easy integration of code with static content, but
if you want your resource to be persistent, don't use them - or at
least, hook them into an object that is persistent in memory.

If you need objects to be persistent in memory, don't use RPYs.

Twisted is not PHP, you can have objects persist in memory without *any
work*. You'd be better off never using RPYs at all, in the vast majority
of cases.

Doing "mktap web --path=foo" and then starting to build your site is
*not* how you should do it. Instead, start with the example code at

 from twisted.web import server, resource
 from twisted.internet import reactor

  class Simple(resource.Resource):
     isLeaf = True
     def render(self, request):
         return "<html>Hello, world!</html>"

  site = server.Site(Simple())
  reactor.listenTCP(8080, site)

Itamar Shtull-Trauring    http://itamarst.org/
http://www.zoteca.com -- Python & Twisted consulting

More information about the Twisted-Python mailing list