Perl Template Toolkit: Now in spicy new Python flavor

E

eefacm

I'd like to inform the Python community that the powerful and popular
Template Toolkit system, previously available only in its original
Perl implementation, is now also available in a beta Python
implementation:

http://tt2.org/python/index.html

I created this port both as a fun programming project, and for use in
environments where Perl is not available, for reasons technical,
cultural, or otherwise. The extensive Perl test suites have also been
ported, and most templates require no or very little modification.

Discussion of the Python implementation should be conducted on the
main Template Toolkit developer mailing list; see the site above for
details.
 
J

Joshua Kugler

I'd like to inform the Python community that the powerful and popular
Template Toolkit system, previously available only in its original
Perl implementation, is now also available in a beta Python
implementation:

http://tt2.org/python/index.html

I created this port both as a fun programming project, and for use in
environments where Perl is not available, for reasons technical,
cultural, or otherwise. The extensive Perl test suites have also been
ported, and most templates require no or very little modification.

I must say...wow. That would have saved me some time and hassle about a
year ago, but of course, I wouldn't have fell in love with pure XML
templates either. :) As someone who has used Template Toolkit quite a bit,
I must say that is is quite cool. Congrats on a job well done!

j
 
G

George Sakkis

I must say...wow. That would have saved me some time and hassle about a
year ago, but of course, I wouldn't have fell in love with pure XML
templates either. :) As someone who has used Template Toolkit quite a bit,
I must say that is is quite cool. Congrats on a job well done!

j

How does it compare with other "mainstream" Python template engines
such as Cheetah, Mako, etc. ? Unless I missed it, the documentation
covers the Perl version only.

George
 
E

eefacm

How does it compare with other "mainstream" Python template engines
such as Cheetah, Mako, etc. ?

I can't claim a comprehensive familiarity with Python template
offerings, but all of the packages approved for use at my previous
workplace left me cold. The most popular were ClearSilver and Django,
and both felt horribly limiting compared to the Template Toolkit,
which I became acquainted with when hacking on Bugzilla some years
ago. Neither supports what I would consider very basic operations on
the template data. Nothing like the following can be expressed in
those packages:


from pprint import PrettyPrinter
from template import Template

print Template().processString(
"the list is [% a.pformat(b(c + d)) %]",
{ "a": PrettyPrinter(2, 40), "b": range, "c": 10, "d": 20 }
)


Here we have a template that includes a method call, a function call,
and simple addition. Neither Django nor ClearSilver can manage any of
these three things. Both of those packages offer other features not
found in the Template Toolkit; it was the relative impotence of the
templating systems that drove me to attack the translation.
Unless I missed it, the documentation
covers the Perl version only.

The online documentation, yes. All source-level documentation (from
which the online documentation is largely drawn) has been converted
into Python docstrings in the source code. They can be read by
browsing the Subversion repository or by importing the code and using
help(); eg:
.... method docs ...
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
I can't claim a comprehensive familiarity with Python template
offerings, but all of the packages approved for use at my previous
workplace left me cold. The most popular were ClearSilver and Django,
and both felt horribly limiting compared to the Template Toolkit,

ClearSilver is not a Python templating system, but a C templating system
with bindings for various languages including Python. Being (by design)
language-agnostic, it's indeed *very* limited (and that's an
understatement).

wrt/ Django templates, it indeed imposes severe limitations on what can
be simply expressed when you are familiar with Python. This is by design
- since it has been designed to be safe to use for non-programmers. Now
while not my cup of tea, it has proven to be fairly usable, quite less
limiting that what I feared at first, and really easy to use for our web
designer/integrator.

Now there are way more flexible/expressive templating systems in Python,
either XML oriented (genshi) or more generic (my favorite one so far
being Mako).

But anyway, I'm not the one that will complain with Perl templating
systems being ported to Python - FWIW, Mako was born from it's author
previous experience with porting Mason to Python !-)
 
P

Paul Boddie

I can't claim a comprehensive familiarity with Python template
offerings, but all of the packages approved for use at my previous
workplace left me cold.

There are a few offerings listed on this page:

http://wiki.python.org/moin/Templating

I suppose you could add Template Toolkit somewhere on that page,
indicating where it fits into the bigger picture.

Paul
 
E

eefacm

The online documentation, yes. All source-level documentation (from
which the online documentation is largely drawn) has been converted
into Python docstrings in the source code.

Augh! And I forgot to mention that there's a file README.python at
the top level of the repository that discusses several of the issues
that arose in converting a large Perl project into Python, and how I
addressed them. Possibly interesting reading.

http://tt2.org/svnweb/Template-Python/view/trunk/README.python
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top