querypy lets you write HTML without actually writing HTML
querypy is a tool that makes it very easy to create W3C-compliant HTML or XHTML-templates by using a short and simple syntax. It is heavily inspired by jquery's "chaining" syntax which makes it possible to chain together multiple operations into short strings of commands.
It should be noted that querypy is not another web framework, or even designed to be used as a way to serve dynamic content. It is simply a tool to help web designers create HTML-layouts in a nice and structured way by using an object oriented tree structure that makes code easy to modify as well as to reuse.
querypy is implemented in python and requires a python interpreter to generate its HTML. Even without prior python knowledge using querypy should be a breeze, but if you are familiar with python you will be able to use your knowledge and do fancy stuff using this library since all tags are regular python objects.
Example usage:
This is a very basic Hello world example using querypy to generate a HTML-file:
from querypy import *
html, head, body = HTML(), HEAD(), BODY()
html + head
html + body
head + ( TITLE() + "A Hello World page" )
body + ( H1() + "Hello world" )
print doctype_html4_strict()
print html
And this is the same example using querypy's two different "chaining" syntaxes:
from querypy import *
print doctype_html4_strict()
print HTML() + ( HEAD() + ( TITLE() + "A Hello World page" ) ) + ( BODY() + ( H1() + "Hello world" ) )
or
from querypy import *
print doctype_html4_strict()
print HTML().add(HEAD().add(TITLE().add("A Hello World page"))).add(BODY().add(H1().add("Hello world")))
All of these three examples will generate the same HTML shown below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>
A Hello World page
</TITLE>
</HEAD>
<BODY>
<H1>
Hello world
</H1>
</BODY>
</HTML>
Chaining is a powerful tool, but can decrease readability when used extensively. Use it with precaution ;)
For more examples and documentation please go to the documentation section of the page