Python Macro

Last modified by Vincent Massol on 2021/03/17 21:54

cogAdds ability to write scripts in Python in wiki pages
Developed by

XWiki Development Team

0 Votes
LicenseGNU Lesser General Public License 2.1
Bundled With

XWiki Standard


This is a shortcut for Script Macro equivalent to {{script language="python"}} to execute python scripts based on any JSR-223 Python provider like Jython.


print "Hello World"

Parameters definition

See the Script Macro for details.


print "Hello World"


Hello World

Why Scripting?

Many different wikis exist to date, each offering a plethora of features.  This example illustrates how leveraging the power of XWiki can save you time, and impress people.  Below is a link to an amusing SMBC comic:

It's entertaining, but the math is awful.  We can actually prove this with python natively in XWiki.  How cool is that?!

I have not included the following script in this page, I've left that for you to try in your own playground.  Go ahead and give it a shot.  Paste the following code into your own XWiki and see what happens.

square = 1
pennies = 1

while square <= 64:
print "Square: %s Pennies: %s" % (square, square)
if square == 1:
  quantity = "penny"
  quantity = "pennies"
print "As of square %s you have %s %s." % (square,pennies,quantity)
print ""
 square += 1
 pennies += square

External Libraries

Using the PyPI Repository

This is the recommended approach. See the PyPI Repository Connector.


External libraries can be used with XWiki by adding them to the proper classpath and importing them.

In order to determine what your classpath and pyclasspath locations are, use the following code:

import sys
print sys.path

Once you have the proper location, you can install your libraries through your normal means (pip, dnf, apt-get, etc), and copy the library to the classpath/pyclasspath locations respectively.  After installation, a restart is required to load the new library/libraries.


Though you can add additional libraries, there may be conflicts that you have to work through to be able to use that library with Xwiki.  An example is the 'boto' library, which conflicts due to function and class definitions that overlap.

Get Connected