Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Take the power of Jinja2 templates to OpenOffice and LibreOffice and create reports and letters in your web applications

Project Description


#### Take the power of Jinja2 templates to OpenOffice and LibreOffice and create reports in your web applications.

Secretary allows you to use Open Document Text (ODT) files as templates for rendering reports or letters. Secretary is an alternative solution for creating office documents and reports in OpenDocument Text format from templates that can be visually composed using the Writer word processor.

Secretary use [the semantics of jinja2 templates][1] to render ODT files. Most features in jinja can be used into your ODT templates including variable printing, filters and flow control.

Rendered documents are produced in ODT format, and can then be converted to PDF, MS Word or other supported formats using the UNO Bridge or a library like [PyODConverter][2]

## Installing

pip install secretary

## Rendering a Template

from secreatary import Render

engine = Render(template) result = engine.render(foo=foo, bar=bar)

Secretary implements a class called Render. Render takes a single argument called template which is a template file. template can be a filename or a file object.

To render a template create an instance of class Render and call the instance’s method render passing the template variables as keyword arguments. render will return the rendered document in binary format.

Before rendering a template, you can configure the internal templating engine using the Render instance’s variable environment, which is an instance of jinja2 [Environment][3] class. For example, to declare a custom filter use:

from secreatary import Render

engine = Render(template)

# Configure custom application filters engine.environment.filters[‘custom_filer’] = filter_function result = engine.render(foo=foo, bar=bar)

output = open(‘rendered_document.odt’, ‘w’) output.write(result)

## Composing Templates

Secretary templates are simple ODT documents. You can create them using Writer. An OpenDocument file is basically a ZIP archive containing some XML files. If you plan to use control flow or conditionals it is a good idea to familiarise yourself a little bit with the OpenDocument XML to understand better what’s going on behind the scenes.

### Printing Variables

Since Secretary use the same template syntax of Jinja2, to print a varible type a double curly braces enclosing the variable, like so:

{{ }} {{ foo[‘bar’] }}

However, mixing template instructions and normal text into the template document may become confusing and clutter the layout. Secretary recommends using an alternative way of inserting fields. Insert a visual field in LibreOffice Writer from the menu Insert > Fields > Other… (or just press Ctrl+F2), then click on the Functions tab and select Input field. Click Insert. A dialog will appear where you can insert the print instructions. You can even insert simple control flow tags to dynamically change what is printed in the field.

Secretary will handle multiline variable values replacing the line breaks with a <text:line-break/> tag.

### Control Flow

To be documented…

### Builtin Filters Apart of the available Jinja2 filters. Secretary includes some additionals filters. These are:

Release history Release notifications

History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


This version
History Node


History Node


History Node


Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
secretary-0.1.0.linux-i686.exe (75.0 kB) Copy SHA256 hash SHA256 Windows Installer any Feb 3, 2014
secretary-0.1.0.tar.gz (26.9 kB) Copy SHA256 hash SHA256 Source None Feb 3, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page