Python Scripts

Tiled ships with a plugin that enables you to use Python 2.7 to add support for custom map formats. This is nice especially since you don’t need to compile Tiled yourself and the scripts are easy to deploy to any platform.

For the scripts to get loaded, they should be placed in ~/.tiled. Tiled watches this directory for changes, so there is no need to restart Tiled after adding or changing scripts (though the directory needs to exist when you start Tiled).

There are several example scripts available in the repository.


On Windows, Python is not installed by default. For the Tiled Python plugin to work, you’ll need to install Python 2.7 (get it from On Linux you may also need to install the appropriate package.

Example Export Plugin

Suppose you’d like to have a map exported in the following format:


You can achieve this by saving the following script in the scripts directory:

from tiled import *

class Example(Plugin):
    def nameFilter(cls):
        return "Example files (*.example)"

    def shortName(cls):
        return "example"

    def write(cls, tileMap, fileName):
        with open(fileName, 'w') as fileHandle:
            for i in range(tileMap.layerCount()):
                if isTileLayerAt(tileMap, i):
                    tileLayer = tileLayerAt(tileMap, i)
                    for y in range(tileLayer.height()):
                        tiles = []
                        for x in range(tileLayer.width()):
                            if tileLayer.cellAt(x, y).tile() != None:
                                tiles.append(str(tileLayer.cellAt(x, y).tile().id()))
                        line = ','.join(tiles)
                        if y == tileLayer.height() - 1:
                            line += ';'
                            line += ','
                        print >>fileHandle, line

        return True

Then you should see an “Example files” entry in the type dropdown when going to File > Export, which allows you to export the map using the above script.


This example does not support the use of group layers, and in fact the script API doesn’t support this yet either. Any help with maintaining the Python plugin would be very appreciated. See open issues related to Python support.

Debugging Your Script

Any errors that happen while parsing or running the script are printed to the Debug Console, which can be enabled in View > Views and Toolbars > Debug Console.

API Reference

It would be nice to have the full API reference documented here, but for now please check out the source file for available classes and methods.