Python Scripting


ThumbsPlus uses Python as its internal scripting language, and you can use it too. Python is not a difficult language to learn, and several of the existing features in ThumbsPlus are written mostly or all in Python.

ThumbsPlus version 8 uses Python version 2.7.1. It is likely that version 9 will use Python 3, but we haven't decided for sure. For information, tutorials, editors and more, please visit the official Python site at

Here is an example script, which moves thumbnails from the database to separate files. This option is designed for Access (.tpdb8) and Sqlite3 (.tpdb8s). Client/server databases should not have any trouble storing many terabytes within the database. The script is stored as:



import sys

import os

import time

import _tpc

import _tp

import _tpd

import tpdb


def move_thumbs():

    _tp.doing_start(u'Moving Thumbnails to External Files'3)


    cnames = _tpd.colnames()

    print cnames

    rowcnt = tpdb.get_count(u'Thumbnail')

    basedir = tpdb.get_db_thumb_path()

    if not os.path.isdir(basedir):


    sqlcmd = u'select idThumb, thumbnail from Thumbnail where Thumbnail.thumbnail is not null'


    while (True):

        rowres = _tpd.fetch()

        if (not rowres):


        id = rowres[0]

        thumb = rowres[1]

        if (thumb == None):

            continue               # Already moved I hope!

        d1 = id / (1627 * 1627);

        d2 = (id - (d1 * (1627 * 1627))) / 1627;

        d3 = id % 1627;

        filename = u'%s\\%03x\\%03x\\' % (basedir, d1, d2, d3)

        if not os.path.isdir(filename[:7]):




                print u'Unable to create folder <%s>' % filename[:7]



            f = open(filename, 'wb')


            print u'Unable to create thumbnail file <%s>' % filename




        done += 1

        _tp.doing_percent(done, rowcnt)

        if _tp.doing_abort():


        tpdb.execute(u'update Thumbnail set Thumbnail.thumbnail = NULL')


    return True