Python CMIS Scripts for Alfresco


CMIS stands for Content Management Interoperability Services.  Using CMIS within Python scripts is a handy way to export/import data from/to Alfresco (or any other CMIS-compliant document management system) or do mass updates of data within Alfresco.  This can be changes to document attributes or even changes to the documents themselves.  If you come from a relational database background, think of CMIS scripts fulfilling a similar role with Alfresco as SQL scripts do with relational databases.

Python cmislib from Apache Chemistry is a CMIS client library for Python.  This tutorial shows you how to install Python and CMIS on a Ubuntu computer.

Why Python?

Python is an elegant readable language, with an emphasis on simplicity, and I think for that reason has become very popular. It is my personal preference for writing CMIS scripts.

From the author: Guido Van Rossum

The Zen of Python:

(You can also use CMIS within java, javascript and PHP.)

Python and CMIS Installation

  • install setuptools for python
sudo apt-get install python python-setuptools
  • install cmislib
sudo easy_install cmislib
  • download the most recent version of cmislib-alfresco-extension
  • install cmislib-alfresco-extension
sudo easy_install

Test Python and CMIS

Test your installation by running the script below that lists the sites in your Alfresco system.

  • paste the code into a file called
  • change the URL to your Alfresco server
  • change the ‘password’ to the correct password for your Alfresco system
#!/usr/bin/env python
# Alfresco extension to CMIS
import cmislibalf

from cmislib import CmisClient, Repository, Folder
from cmislib.model import CmisId
from cmislib.exceptions import CmisException, UpdateConflictException
import os, sys

  client = CmisClient('', 'admin', 'password')
  repo = client.defaultRepository
  print "failed to connect to Alfresco"

  print 'Getting list of sites ..'
  folders = repo.query("select * from cmis:folder where cmis:objectTypeId='F:st:site'")
  print 'Processing list ..'
  for folder in folders:
    obj = repo.getObject(
    # properties items are key-value TUPLES ..
    for key,val in
      if key=='cm:name' or key=='cm:title' or key=='cmis:path':
        print key,'=',val
except ValueError:
  print "failed to read site list"
  • make executable
chmod +x
  • run the script
  • output from the script will look something like ..
Getting list ..
Processing list ..
cmis:path = /Sites/swsdp
cm:title = Sample: Web Site Design Project
cmis:path = /Sites/gpc
cm:title = GPC
cmis:path = /Sites/digs
cm:title = DIGS

Other Resources

Apache Chemistry has some good tutorials and example code ..

CMIS Workbench is a great tool for querying Alfresco and doing quick edits.  It is also a very useful tool for determining attributes of objects while writing CMIS scripts.  You can download from

CMIS Workbench

Screenshot of CMIS Workbench

Order of the Bee – an independent organisation of the Alfresco community. Web-site includes good technical and non-technical posts and other information, focussed mainly on Alfresco Community Edition (CE).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s