Skip to main content

Python docx template engine

Project description

Use a docx as a jinja2 template

Introduction

This package uses 2 major packages :

  • python-docx for reading, writing and creating sub documents

  • jinja2 for managing tags inserted into the template docx

python-docx-template has been created because python-docx is powerful for creating documents but not for modifying them.

The idea is to begin to create an example of the document you want to generate with microsoft word, it can be as complex as you want : pictures, index tables, footer, header, variables, anything you can do with word. Then, as you are still editing the document with microsoft word, you insert jinja2-like tags directly in the document. You save the document as a .docx file (xml format) : it will be your .docx template file.

Now you can use python-docx-template to generate as many word documents you want from this .docx template and context variables you will associate.

Share

If you like this project, please rate and share it here : http://rate.re/github/elapouya/python-docx-template

Documentation

Please, read the doc

News

0.6.2 (2019-06-09)

  • Handle spaces correctly when run are split by Jinja code (#205)

0.6.1 (2019-06-05)

  • PR #203

0.6.0 (2019-06-03)

  • DocxTemplate now accepts file-like objects (Thanks to edufresne)

0.5.20 (2019-05-23)

  • Fix #199

0.5.19 (2019-05-23)

  • Add support for file-like objects for replace_media (#197)

0.5.18 (2019-05-20)

  • Fix #176

0.5.17 (2019-01-20)

  • Delegated autoescaping to Jinja2 Environment (#175)

0.5.16 (2019-01-11)

  • Force to use python-docx 0.8.7 (#170)

  • Add getting undeclared variables in the template (#171)

0.5.15 (2019-01-02)

  • Added PAGE_BREAK feature (#168)

0.5.14 (2018-12-23)

  • Fixed issue #159: autoescaped values for both str and unicode.

0.5.12 (2018-12-18)

  • Fix tables with gridSpan that have less cells after the tc forloop (#164)

0.5.11 (2018-11-21)

  • Smart double quotes in jinja tags are now converted into simple double quotes

0.5.10 (2018-11-20)

  • Smart quotes in jinja tags are now converted into simple quotes

  • Add custom jinja filter example in tests/

  • Reformat the code to be a little more PEP8 compliant

0.5.9 (2018-11-18)

  • Add {% hm %} tag for table columns horizontal merging (Thanks to nickgashkov)

  • Split tests/tests_files dir into templates and output dirs

0.5.8 (2018-11-08)

  • autoescape support for python 2.7

  • fix issue #154

0.5.7 (2018-11-07)

  • Render can now autoescape context dict

0.5.6 (2018-10-18)

  • Fix invalid xml parse because using {% vm %}

0.5.5 (2018-10-05)

  • Cast to string non-string value given to RichText or Listing objects

  • Import html.escape instead of cgi.escape (deprecated)

0.5.4 (2018-09-19)

  • Declare package as python2 and python3 compatible for wheel distrib

0.5.3 (2018-09-19)

  • Add sub/superscript in RichText

0.5.2 (2018-09-13)

  • Fix table vertical merge

0.5.0 (2018-08-03)

  • An hyperlink can now be used in RichText

0.4.13 (2018-06-21)

  • Subdocument can now be based on an existing docx

  • Add font option in RichText

  • Better tabs and spaces management for MS Word 2016

  • Wheel distribution

  • Manage autoscaping on InlineImage, Richtext and Subdoc

  • Purge MANIFEST.in file

  • Accept variables starting with ‘r’ in {{}} when no space after {{

  • Remove debug traces

  • Add {% vm %} to merge cell vertically within a loop (Thanks to Arthaslixin)

  • use six.iteritems() instead of iteritems for python 3 compatibility

  • Fixed Bug #95 on replace_pic() method

  • Add replace_pic() method to replace pictures from its filename (Thanks to Riccardo Gusmeroli)

  • Improve image attachment for InlineImage ojects

  • Add replace_media() method (useful for header/footer images)

  • Add replace_embedded() method (useful for embedding docx)

0.3.9 (2017-06-27)

  • Fix exception in fix_table()

  • Fix bug when using more than one {{r }} or {%r %} in the same run

  • Fix git tag v0.3.6 was in fact for 0.3.5 package version so create a tag 0.3.7 for 0.3.7 package version

  • Better head/footer jinja2 handling (Thanks to hugokernel)

  • Fix bug where one is using ‘%’ (modulo operator) inside a tag

  • Add Listing class to manage n and a (new paragraph) and escape text AND keep current styling

  • Add {%tc } tags for dynamic table columns (Thanks to majkls23)

  • Remove version limitation over sphinx package in setup.py

  • Add PNG & JPEG in tests/test_files/

  • You can now add images directly without using subdoc, it is much more faster.

0.2.5 (2017-01-14)

  • Add dynamic colspan tag for tables

  • Fix /n in RichText class

  • Add Python 3 support for footer and header

  • Fix bug when using utf-8 chracters inside footer or header in .docx template It now detects header/footer encoding automatically

  • Fix bug where using subdocs is corrupting header and footer in generated docx Thanks to Denny Weinberg for his help.

  • Add Header and Footer support (Thanks to Denny Weinberg)

0.1.11 (2016-03-1)

  • ‘>’ and ‘<’ can now be used inside jinja tags

  • render() accepts optionnal jinja_env argument : useful to set custom filters and other things

  • better subdoc management : accept tables

  • better xml code cleaning around Jinja2 tags

  • python 3 support

  • remove debug code

  • add lxml dependency

  • fix template filter with quote

  • add RichText support

  • add subdoc support

  • add some exemples in tests/

  • First running version

Project details


Release history Release notifications | RSS feed

This version

0.6.2

Download files

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

Source Distribution

docxtpl-0.6.2.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

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

docxtpl-0.6.2-py2.py3-none-any.whl (21.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file docxtpl-0.6.2.tar.gz.

File metadata

  • Download URL: docxtpl-0.6.2.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for docxtpl-0.6.2.tar.gz
Algorithm Hash digest
SHA256 ed273fbf355d4db6c330b943b9eaf9056792ee17504e003585477cfba5adac40
MD5 3186665c967ff321344c617cfb030af3
BLAKE2b-256 955282d1263c906049a9537cb86d3fce84ad8d5fe1308b7cb35882f27c63d47b

See more details on using hashes here.

File details

Details for the file docxtpl-0.6.2-py2.py3-none-any.whl.

File metadata

  • Download URL: docxtpl-0.6.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for docxtpl-0.6.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 eb307fc0f38ee78bc4a2b08d0aa2ae69cc10add7be23fe204a5a9851946c960f
MD5 9a5067a17acc838366063caa79e48478
BLAKE2b-256 99532eb8213ee338a28db84f8f6a5ac96d4975ffde0db42b7f73ac25e8317472

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