Nuxeo Python Client - A Python Client Library for Nuxeo Automation and REST API


Tue 24 May 2016 By Rémi Cattiau

The Nuxeo Platform has a number of great REST APIs that you can use to automate and integrate your repository with the rest of your IT.

When Nuxeo Drive was first built, the developers who worked on it, Antoine and Olivier, started the first client to this API as an underlying layer of the Drive client. It survived every refactoring done so far on Drive and hasn't evolved much since its creation.

Meanwhile, Nuxeo developed a really cool Object oriented Nuxeo JS Client using Promise, soon followed by its big brother the Nuxeo Java Client. For a while we had the extraction of the Python one to make a standalone client in our Drive backlog.

So here we are now: we have extracted this client, refactored it, and added cool features to have a third member in the family, a Python one!

Released on 5/9/2016, the v1.0.0 is available in your favorite Python dependencies manager: pip

Here's how you can install it:

pip install nuxeo-python-client

Now we can simply import, connect, and play!

from nuxeo.nuxeo import Nuxeo

nuxeo = new Nuxeo( auth={
    username: 'Administrator',
    password: 'Administrator'
  })

Let's create a new folder, and a document

newFolder = {
  'entity-type': 'document',
  name: 'a-folder',
  type: 'Folder',
  properties: {
    'dc:title': 'foo',
  }
}
folder = nuxeo.repository().create('/', newFolder)

doc = nuxeo.repository().fetch('/')
doc.set({ 'dc:title': 'foo' })
doc.save()

We can then use our converter to get a PDF version of an HTML file. For example:

from nuxeo.blob import FileBlob
blob = FileBlob('mypage.html')
uploaded = nuxeo.batchUpload().upload(blob)
operation = nuxeo.operation('Blob.AttachOnDocument')
operation.params({'document':'/foo'})
operation.input(uploaded)
operation.execute()

doc.convert({ format: 'pdf' })

You have access to a lot more features, such as, workflows, ACL, locking, etc.

The documentation (generated using sphinx) can be found here, and the source on GitHub.


Tagged: Nuxeo Automation, REST API