Skip to main content

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

Metadata

Release files for airspeed 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airspeed 0.7.1
File Size Uploaded
airspeed-0.7.1.tar.gz 16.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for airspeed 0.7.1
File Interpreter ABI Platform
airspeed-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.2 kB

Release files / airspeed-0.7.1.tar.gz

Download URL airspeed-0.7.1.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7b7bf93db92e9dc60d64b193af971950bc6764c28e0d6143698d27a3b7f48cf5
BLAKE2b-256 checksum
How to use checksums
8a29895191cd1f2e28c61a5e4a07c7fbfb3ee3e5f7730cbaac643c9b149d2060
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.11

Release files / airspeed-0.7.1-py3-none-any.whl

Download URL airspeed-0.7.1-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40787897d4490142c6abd6bee10172dc548c2b6b2ab7a225ae0231f3fcf068d4
BLAKE2b-256 checksum
How to use checksums
5eabed3c4f9609bd53de83fa761902c9adfae46b95b4614f4d55f037eb00e01e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

1 release file

0.5.20

1 release file

0.5.19

1 release file

0.5.18

1 release file

0.5.17

1 release file

0.5.16

1 release file

0.5.15

1 release file

0.5.14

1 release file

0.5.13

2 release files

0.5.12

2 release files

0.5.11

2 release files

0.5.10

3 release files

0.5.9

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page