Skip to main content

Airspeed is a powerful and easy-to-use templating engine for Python that aims for a high level of compatibility with the popular Velocity library for Java.

Project description

Build Status PyPI version PyPi downloads Support me

Airspeed - a Python template engine

What is Airspeed?

Airspeed is a powerful and easy-to-use templating engine for Python that aims for a high level of compatibility with the popular Velocity library for Java.

Selling points

  • Compatible with Velocity templates
  • Compatible with Python 2.7 and greater, including Jython
  • Features include macros definitions, conditionals, sub-templates and much more
  • Airspeed is already being put to serious use
  • Comprehensive set of unit tests; the entire library was written test-first
  • Reasonably fast
  • A single Python module of a few kilobytes, and not the 500kb of Velocity
  • Liberal licence (BSD-style)

Why another templating engine?

A number of excellent templating mechanisms already exist for Python, including Cheetah, which has a syntax similar to Airspeed.

However, in making Airspeed's syntax identical to that of Velocity, our goal is to allow Python programmers to prototype, replace or extend Java code that relies on Velocity.

A simple example:

t = airspeed.Template("""
Old people:
#foreach ($person in $people)
 #if($person.age > 70)
  $person.name
 #end
#end

Third person is $people[2].name
""")
people = [{'name': 'Bill', 'age': 100}, {'name': 'Bob', 'age': 90}, {'name': 'Mark', 'age': 25}]
print t.merge(locals())

You can also use "Loaders" to allow templates to include each other using the #include or #parse directives:

% cat /tmp/1.txt
Bingo!
% cat /tmp/2.txt
#parse ("2.txt")
% python
Python 2.4.4 (#1, May 28 2007, 00:47:43)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from airspeed import CachingFileLoader
>>> loader = CachingFileLoader("/tmp")
>>> template = loader.load_template("1.txt")
>>> template.merge({}, loader=loader)
'Bingo!\n'

How compatible is Airspeed with Velocity?

All Airspeed templates should work correctly with Velocity. The vast majority of Velocity templates will work correctly with Airspeed.

What does and doesn't work?

Airspeed currently implements a very significant subset of the Velocity functionality, including $variables, the #if, #foreach, #macro, #include and #parse directives, and "$interpolated #strings()". Templates are unicode-safe.

The output of templates in Airspeed is not yet 'whitespace compatible' with Velocity's rendering of the same templates, which generally does not matter for web applications.

Where do I get it?

https://github.com/purcell/airspeed

Getting started

The Velocity User Guide shows how to write templates. Our unit tests show how to use the templates from your code.

Reporting bugs

Please feel free to create tickets for bugs or desired features.

Who is to blame?

Airspeed was conceived by Chris Tarttelin, and implemented jointly in a test-driven manner by Steve Purcell and Chris Tarttelin. We can be contacted by e-mail by using our first names (at) pythonconsulting dot com.

Extensions for compatibility with Velocity 1.7 were kindly provided by Giannis Dzegoutanis, and further modernization has been done by David Black.


💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airspeed-0.6.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airspeed-0.6.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file airspeed-0.6.1.tar.gz.

File metadata

  • Download URL: airspeed-0.6.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for airspeed-0.6.1.tar.gz
Algorithm Hash digest
SHA256 119a922875d82431003d2f7115c91b6601e8f01779f141c6807329d1fc9239e7
MD5 a430a2bd7def01c9435a71d5ebd582c5
BLAKE2b-256 52b424f00108d9326452219d67f7d72ab617405e40efee19a8e24edf9baa4697

See more details on using hashes here.

File details

Details for the file airspeed-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: airspeed-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for airspeed-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed8a610dc981308a3eed4c7fa607bba8f833a3941f4435b027d08785da85566d
MD5 732d757379620181b705f72103ec0e4b
BLAKE2b-256 669d64a3acca4a76daf13da0ef06f54cf63799ac29cd2435a1226f03d634ea33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page