#from Cheetah.Utils.htmlEncode import htmlEncode #################### ## Class attributes: #attr navBarSep = '|' #attr title = 'Cheetah - The Python-Powered Template Engine' #attr htmlExt = '.html' #attr pageId = 'index' ## $apos used to avoid a syntax highlight issue in Emacs: #attr apos = ''' #attr currentYear = time.strftime("%Y",time.localtime(time.time())) ################################################################################ ## Everything outsite of '#blocks' from here to the next set of 3 commment bars ## is part of the template's .respond() method. .respond() is the default ## method and is linked into the template's __str__ method. ################################################################################ #block doctypeEtc #end block #block headTagContents $title #end block headTagContents #block bodyTag: #block body #block banner #end block banner
#block navBar #set pages = [page.split(',') for page in [ 'index,Overview', 'download,Download', 'learn,Docs', 'examples,Examples', 'whouses,Who Uses It?', 'praise,Testimonials', 'contribute,Help Out', ]] ## pageInnerWrapper1
## pageInnerWrapper0 #block footer #end block footer
## pageOuterWrapper #end block body ################################################################################ ## The contents for each page: ################################################################################ #def indexPageContents

Cheetah is an open source template engine and code generation tool written in Python. It can be used standalone or combined with other tools and frameworks. Web development is its principle use, but Cheetah is very flexible and is also being used to generate C++ game code, Java, sql, form emails and even Python code.

Cheetah has a large and active user community. Products built with Cheetah are used by many of the Fortune 500. One prominent new user is reddit.com, a startup funded by Paul Graham.

#set sep=' | '
$shortPraiseSection
read more quotes
Download Cheetah 2.0rc2 (released on Jan 13, 2006): major feature enhancements.
##################################################

Cheetah:

##################################################

What is the philosophy behind Cheetah?

Its design was guided by these principles:

#end def ################################################################################ #def creditsPageContents

Cheetah was created by Tavis Rudd, a freelance programmer and designer, with contributions from many open source volunteers. Its documentation is edited by Mike Orr, who also wrote its command line tool.

We$(apos)d like to thank the following people for contributing valuable advice, encouragement, code and bug reports:

The Velocity, WebMacro, Smarty and Mason projects provided inspiration and design ideas. Cheetah has benefited from the creativity and energy of their developers. Thank you.

On a historical note, Cheetah is one of several templating frameworks that grew out of a "templates" thread on the Webware for Python email list.

#end def ################################################################################ #def learnPageContents

Official Documentation

Note, the official documentation describes Cheetah 1.0. We are in the process of updating it to include the changes in the 2.0 release. For the time-being, the changes in 2.0 are described in the module docstrings and in the CHANGES log.

Cheetah Users' Guide: ##' HTML Multi-page HTML Postscript Text PDF

Cheetah Developers$(apos) Guide: HTML Multi-page HTML Postscript Text PDF

Also see the latest CHANGES, TODO, BUGS.

The LaTeX source for the Users' Guide and Developers' Guide is in the CVS module CheetahDocs at SourceForge, http://sourceforge.net/cvs/?group_id=28961.

Unofficial Documentation and Articles

Building and filling out templates with Python and Cheetah by Leonard Richardson, Software Engineer at CollabNet. Published in IBM Developer Works, August 9th, 2005. Leonard Richardson is the author of many Python applications and libraries, including NewsBruiser and Beautiful Soup. He is a co-author of the new tome Beginning Python, from Wrox.

Python-Powered Templates with Cheetah by Andrew Glover, founder and CTO of Vanward Technologies, a company specializing in building automated testing frameworks. Published in O'Reilly's ONLamp.com, January 13th, 2005

Templating with Cheetah, a DevShed article by Peyton McCullough. Published in December 2005.

The Python10 conference paper about Cheetah, by Tavis Rudd, Mike Orr, and Ian Bicking. It provides a high-level introduction to Cheetah and the philosophy behind its design. Published in December 2001.

Templating in Python, a Linux Gazette article by Mike Orr. Published in Issue 117 of Linux Gazette, August 2005.

Tierisch gut Das Cheetah Templating-System in der Praxis, a German-language article by Markus Jais. Published in the December 2004 edition of http://www.linuxenterprise.de/.

One-Page Tutorial for template maintainers. Covers a few basic concepts.

Python Success Stories: Python Enterprise-Wide at the University of St Andrews in Scotland by Hamish Lawson. Cheetah is used for the presentation layer. Hamish Lawson is a software developer in the IT Services department at the University of St Andrews, Scotland. Published January 17th, 2003.

Code Generation Network - Case Study with Peter White, an interview that discusses using Cheetah for generating Java code in a financial services application. "Given my recent experience with Python and Cheetah, I can't imagine an easier way to generate code!" Published March 1st, 2004.

Cheetah is covered in Python in a Nutshell, by Alex Martelli. Alex writes on the Cheetah list: "Nutshell readers looking for templating engines will be tempted by my ultra-brief coverage enough to come visit the Cheetah site and get stunned. Indeed, I'm impressed enough that I plan to cover _only_ Cheetah as the one tool for any serious templating need."

It is also introduced in the New Riders book Python Web Programming, by Steve Holden. Steve writes "Although the software is still in beta at the time of writing, it is already stable and easy to use either with or without Webware. It looks as though Cheetah will be useful to many web projects, as well as any others that need flexible template substitution of a general nature." Published Jan 8th, 2002.

#end def ################################################################################ #def downloadPageContents

The most recent stable release was 1.0 on Dec 4, 2005. Don$(apos)t let the version number fool you. Cheetah has been stable, production quality, post-beta code since 2001. All new releases since then (40+) have been almost 100% backwards compatible.

The most recent development release was 2.0rc2 on Jan 13, 2006.

Here$(apos)s the documentation on recent changes.

You can also get the current unreleased development version of Cheetah from our CVS repository.

Cheetah is included in FreeBSD and most major Linux distributions: Gentoo, Fedora, Debian, and Ubuntu among others.

IMPORTANT NOTE TO WINDOWS USERS: If you are using windows and Python 2.4, you should either use one of the .exe releases or grab _namemapper.pyd from the 0.9.17rc1 release and install it wherever your system puts Cheetah/NameMapper.py. This is a compiled copy of the C version of NameMapper (provided by Kevin Dangoor). Using it results in dramatic performance benefits.

#end def ################################################################################ #def examplesPageContents

Here's a very simple example that illustrates some of Cheetah's basic syntax:

#call htmlEncode
  #raw
  
    $title
    
      
        #for $client in $clients
        
        #end for
      
$client.surname, $client.firstname $client.email
#end raw #end call

Compare this with PSP:

#call htmlEncode
  #raw
  
    <%=title%>
    
      
        <% for client in clients: %>
        
        <%end%>
      
<%=client['surname']%>, <%=client'[firstname']%> <%=client['email']%>
#end raw #end call

See the documentation for more examples.

#end def ################################################################################ #def whousesPageContents ###

Cheetah is being used in a wide variety of commercial, government, academic, personal, and open-source projects & products. Products built with Cheetah are used by many of the Fortune 500.

This page provides selected examples. It is not an exhaustive list. If you use Cheetah and wish to be added here, please send an email to the mailing list.

  • One major example of commercial use are the email gateway appliances from IronPort Systems, which are used by the largest corporations and ISPs in the world. IronPort$(apos)s products contain over a million lines of Python and use Cheetah plus Aquarium for their user interfaces.
  • A prominent example of government use is Incident News, which provides news, photos, and other information about spill incidents and response actions in the U.S. A larger private site is used to feed the items on the public site. The site is maintained by the Hazardous Materials Response Division, Office of Response and Restoration, National Ocean Service, National Oceanic and Atmospheric Administration (NOAA), in support of U.S. Coast Guard incident response operations.
  • The University of St. Andrews, in Scotland, uses Python + Cheetah for their student records system. St. Andrews is the 3rd oldest university in the English speaking world. See this write-up for details.
  • It is supported by, and used with, every major Python web development framework:
      #call self.displayLinesAsList $pythonFrameworksUsing(includeWrapperText=False,sep='',includeWebwareInList=True) #end call
  • Cheetah is included in FreeBSD and most major Linux distributions: Gentoo, Fedora, Debian, and Ubuntu among others.
  • #call self.displayLinesAsList PatientWire reddit.com Gentoo Linux $makeLink('http://bosco.tigris.org/') A JMI-compliant template-based code generator. #slurp It reads XMI files and generates the corresponding source code, #slurp in different object-oriented languages (Java, Eiffel, Python, C++). #slurp In the case of Java, the generated code implements the JMI interfaces. $makeLink('http://www.intertwingly.net/blog/') (blog of Sam Ruby, Apache Foundation Director) $makeLink('http://www.electronicappraiser.com/') $makeLink('http://www.instasong.com/InstaSong/') $makeLink('http://www.axiomfire.com/') All internal tools and live eDialogues built with Cheetah $makeLink('http://initd.org/') (makers of psycopg and pysqlite) $makeLink('http://www.asti-usa.com/') #slurp (Andrew Kuchling is currently porting their large web app to Cheetah) $makeLink('http://snurf.bdash.net.nz/') a Python-based blogging system $makeLink('http://linuxgazette.com/') $makeLink('http://pyblosxom.sourceforge.net/') $makeLink('http://pyds.muensterland.org/') $makeLink('http://faces.homeip.net/') $makeLink('http://map.wirelesslondon.info/') $makeLink('http://tboard.sourceforge.net/') $makeLink('http://singleshot.org/') $makeLink('http://www.python-hosting.com/') $makeLink('http://www.petersblog.org/') ###$makeLink('http://www.usenix.org/events/lisa03/tech/' ##'full_papers/giridharagopal/giridharagopal_html/') $makeLink('http://tools.arlut.utexas.edu/DryDock/') #slurp a large web-publishing application focussed on workflow $makeLink('http://wiki.osuosl.org/display/DEV/OJBDoc') #end call
  • Cheetah supports internationalization and has a large non-English userbase, including:
      #call self.displayLinesAsList $makeLink('http://www.alqua.org/') (Spanish) $makeLink('http://bank.muratordom.pl/') (Polish) $makeLink('http://bank.muratorplus.pl/') (Polish) $makeLink('http://www.encyclon.net/multiblast') (Korean) Bioinformatics Tool $makeLink('http://www.aufeinander.de/') (German) $makeLink('http://www.katechese.at/') (German) $makeLink('http://www.herschberger.at/') (German) $makeLink('http://www.oejhw.or.at/') (German) $makeLink('http://www.go-direct.at/') (German) $makeLink('http://www.dmvoe.at/') (German) $makeLink('http://seps.flibuste.net/') (French) $makeLink('http://flibuste.net/') (French) $makeLink('http://www.tac.cz/') (Czech) $makeLink('http://www.cestovatel.cz/') (Czech) $makeLink('http://www.iddk.ru/') (Russian) $makeLink('http://shop.iddk.ru/') (Russian) $makeLink('http://ustawki.net/') game-manager for soccer fans (Czech?) #end call
    #call self.displayLinesAsList Dell CNN NASDAQ Ebay Sony EDS GAP Maytag PayPal Juniper Road Runner Whirlpool Capital One Liberty Mutual Continental Airlines General Foods Prudential Financial Aetna Imperial Optical Wolf Bioscience Hundreds of eye-care practices John Hopkins University Harvard University University of St. Andrews University of British Columbia Ryder AON Franklin Templeton Investments Manulife Societe Generale Juniper Networks Masco ADP Liberty Mutual RJ Renolds Charter Communications BNP Paribas L.A. Care Health Plan Salt Lake County Grand Prairie ISD ASTi Reddit.com LinuxGazette.com HFD.com #end call
#end def ################################################################################ #def contributePageContents

Cheetah is the work of many volunteers. If you use Cheetah, share your experiences, tricks, customizations, and frustrations. Please join the mailing list.

Publicity

Help spread the word: blog about it, write articles about it, recommend it to others, etc.

Bug reports and patches

If you think there is a bug in Cheetah, send a message to the email list with the following information:

  1. a description of what you were trying to do and what happened
  2. all tracebacks and error output
  3. your version of Cheetah
  4. your version of Python
  5. your operating system
  6. whether you have changed anything in the Cheetah installation

Example sites and tutorials

If you$(apos)re developing a website with Cheetah, please send a link to the email list so we can keep track of Cheetah sites. Also, if you discover new and interesting ways to use Cheetah please share your experience and write a quick tutorial about your technique.

Test cases

Cheetah is packaged with a regression testing suite that is run with each new release to ensure that everything is working as expected and that recent changes haven$(apos)t broken anything. The test cases are in the Cheetah.Tests module. If you find a reproduceable bug please consider writing a test case that will pass only when the bug is fixed. Send any new test cases to the email list with the subject-line "new test case for Cheetah."

#end def ################################################################################ #def praisePageContents #call $shortPraiseSection $formatQuote("There is no better solution than Cheetah.", 'Wilk') ##http://www.pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib/example-file-web-template-cheetah.html $formatQuote("Cheetah is a powerful, stable and well documented templating system.", 'James Gardner') ##http://keithdevens.com/weblog/archive/2003/Nov/17/Python.Cheetah $formatQuote("Cheetah is very nice. Good code even!", 'Keith Devens') $formatQuote("""People with a strong PHP background absolutely love Cheetah for being Smarty, but much, much better.""", 'Marek Baczynski') ##post on cheetah list about initd.org $formatQuote('i did it in a single night (i _love_ cheetah templates ;)', 'Federico Di Gregorio, developer of psycopg') $formatQuote("""Cheetah seems to be practically the only web templating format with decent taste. On top of that, it doesn't try to limit the programmers with needless restrictions and hoops. ... reddit.com was recently rewritten with Python and Cheetah Templates. The project seems to have gone really well and the former-Lisp developers really enjoyed Cheetah's simple syntax.""", '''Aaron Swartz, co-author of the RSS 1.0 spec''') $formatQuote("""I am using Smarty and I know it very well, but compiled Cheetah Templates with its inheritance approach is much powerful and easier to use than Smarty.""", 'Jaroslaw Zabiello') $formatQuote("""A cheetah template can inherit from a python class, or a cheetah template, and a Python class can inherit from a cheetah template. This brings the full power of OO programming facilities to the templating system, and simply blows away other templating systems.""", 'Mike Meyer') $formatQuote('Love your work guys.', 'Alex Le Dain') $formatQuote("""I'm trying code generation with Cheetah. I have to say it's a pleasure compared to XSLT!""", 'Alex J. Champandard') $formatQuote("""Cheetah has successfully been introduced as a replacement for the overweight XSL Templates for code generation. Despite the power of XSL (and notably XPath expressions), code generation is better suited to Cheetah as templates are much easier to implement and manage.""", '''The FEAR development team''') ##http://www.thescripts.com/forum/post365058-2.html $formatQuote("I'm greatly in favour of Cheetah.", 'Sybren Stuvel') ##http://www.codegeneration.net/tiki-read_article.php?articleId=39 $formatQuote("""I ran across Cheetah, 'a Python-powered template engine and code generator', and haven't looked back since. ... it was a breeze to crank out several templates in a short period of time. In only a few hours a night, over three nights, I was able to learn enough about Python and Cheetah to write a code generator that generates my POJOs, DAOs, and WebWork2 action classes. ... Given my recent experience with Python and Cheetah, I can't imagine an easier way to generate code! """, '''Peter White, in an interview on the "Code Generation Network"''') ##http://blog.kodemaniak.de/archives/10-Python-template-system.html $formatQuote("Cheetah is very powerful and flexible.", 'Carsten Saathoff') ## http://groups.google.com/group/turbogears/tree/browse_frm/thread/bb7a6115ca7028c9/4bd4ca24aa61d75c?rnum=111&q=cheetah+python&_done=%2Fgroup%2Fturbogears%2Fbrowse_frm%2Fthread%2Fbb7a6115ca7028c9%2F7bffb1c3622af7a4%3Flnk%3Dst%26q%3Dcheetah+python%26rnum%3D9%26#doc_7bffb1c3622af7a4 $formatQuote("I've used Cheetah quite a bit and it's a very good package.", 'Kevin Dangoor, lead developer of TurboGears') $formatQuote("""Cheetah is an extremely effective Python-powered template engine that can generate any text-based format. Cheetah's impressive yet simple template language (based on Python) can yield the most complex of documents ... Cheetah is surprisingly simple to use""", c'''Andrew Glover, in an article published on O$(apos)Reilly ONLamp.com''') ##http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/4865ad8dced9d4db/133ada37370deb55?rnum=1&q=cheetah+python&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F4865ad8dced9d4db%2Ff932e1952225168c%3Flnk%3Dst%26q%3Dcheetah+python%26rnum%3D95%26#doc_f932e1952225168c $formatQuote("Regarding the template engine, the best one I'm aware of is Cheetah.", 'Alessandro Bottoni') $formatQuote("""Just a quick note to say thanks for the work you've put into Cheetah. I had this unholy hack of several perl scripts to do my html templating. After seeing the light and moving to Python, I dreaded rewriting all of that working code. But, after finding Cheetah, I seriously had something working in under an hour that is way better than all of those perl scripts that took me weeks to write. Awesome stuff.""", "Rob McMullen") $formatQuote("""I write to say THANK YOU again! I'm very pleased to see such a friendly community. I appreciate your help! =)""", 'Timur Izhbulatov') $formatQuote("""I hand it to the makers: Cheetah is great stuff. I've used WebMacro for years and this even improves on it. Specifically I like the blocks/functions and the ability to dynamically derive (thanks to python for that""", 'Torsten Rueger') ##http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/eac957ba7c426e30/3ebe6739c8c41752?rnum=31&q=cheetah+python&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Feac957ba7c426e30%2Fa3b9cd8f6cc9e640%3Flnk%3Dst%26q%3Dcheetah+python%26rnum%3D12%26#doc_c166b21577e3ad06 $formatQuote("""But, the problem is PHP itself has so many bad features that I prefer rather Python to PHP. And I like Cheetah's inheritence aproach because it is scales very well for complicated web pages. I can develop internet application much faster using Python (e.g. using application, very cool and pythonic Cherry2) and Cheetah. And because extending templates using OO techniques is tthe feature I like, I would rather choose Cheetach than ZPT, SimleTAL, Nevow and similar solutions.""", 'Jaroslaw Zabiello') ## http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/adbc3058a431f1b8/5b49623e0a8c782c?rnum=31&q=cheetah+template&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2Fadbc3058a431f1b8%2F3a45e7ec2e495bd2%3Flnk%3Dst%26q%3Dcheetah+template%26rnum%3D67%26#doc_3a45e7ec2e495bd2 $formatQuote("""Another great bonus of Spyce is that it can work with Cheetah, the one templating system which I felt like I could live with.""", 'Jonathan P.') ## http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/6ac8c68b6060003e/f3a99fd7ec17d6d5?rnum=1&q=cheetah+template&_done=%2Fgroup%2Fcomp.lang.python%2Fbrowse_frm%2Fthread%2F6ac8c68b6060003e%2F40fe71c3d3ab0bd8%3Flnk%3Dst%26q%3Dcheetah+template%26rnum%3D22%26#doc_40fe71c3d3ab0bd8 $formatQuote( """My graphist and me found it excellent, fast, clear, simple, stable: Pythonic! We found the others engines too verbose ... I use it to generate html, latex and xml""", 'Wilk') $formatQuote("""I was going to try and learn Kid, but I'm in a bit of a hurry, and Cheetah's much closer to what I'm used to.""", 'Dave Benjamin') $formatQuote("""Personally, I prefer to Cheetah Templates to PSP - it plays better in the OO world, and I can use intelligent HTML/XML/SGML editors on the files.""", 'Mike Meyer') #end call #end def ################################################################################ ## Helper methods & content snippets used in multiple places ################################################################################ #def displayLinesAsList(arg): #for ln in arg.splitlines() #set ln = $ln.strip #if not ln #continue #end if
  • $ln.strip
  • #end for #end def #def makeLink(link, title=None) #if title then title else link# #slurp #end def ################################################################################ #def formatQuote(quote, citation)
    “$quote”
    -$citation
    #end def ################################################################################ #def shortPraiseSection(extraItems=None) $formatQuote("I'm enamored with Cheetah", '''Sam Ruby, senior member of IBM\'s Emerging Technologies Group & director of Apache Software Foundation''') $formatQuote("""Give Cheetah a try. You won't regret it. ... Cheetah is a truly powerful system. ... Cheetah is a serious contender for the 'best of breed' Python templating.""", '''Alex Martelli, Google uber techie, core Python developer & author of several popular Python books''') #if extraItems then extraItems else '' #end def ################################################################################ #def sourceforgeWebBug SourceForge.net Logo #end def ################################################################################ #def pythonFrameworksUsing(includeWrapperText=True, sep=',', includeWebwareInList=False) #if includeWrapperText

    Cheetah was originally designed to integrate with Webware for Python, a Python-powered application server, but it can be used with any Python web framework. It is being used with #end if #if includeWebwareInList Webware for Python$sep #end if Aquarium$sep mod_python$sep Quixote$sep CherryPy, TurboGears$sep Django$sep Paste$sep Subway$sep Python Web Modules$sep Spyce$sep Tahchee$sep plain-old-cgi$sep #if includeWrapperText and others. Most of these frameworks provide automatic session, cookie, and user management and can be used with almost any operating-system, web server, or database.

    #end if #end def