Client SDKs

Python Client

Updated: December 8, 2016 Page Information Edit on GitHub

Client Library for Nuxeo API

Build Status

The Nuxeo Python Client is a Python client library for the Nuxeo Automation and REST API.

This is an on-going project, supported by Nuxeo.

Getting Started

After installing Python, use pip to install the nuxeo-python-client package:

$ pip install nuxeo-python-client

Then, use the following import statement to have access to the Nuxeo API:

from nuxeo.nuxeo import Nuxeo

Documentation

Check out the API documentation.

Requirements

The Nuxeo Python client works only with Nuxeo Platform >= LTS 2015.

Quick Start

This quick start guide will show how to do basics operations using the client.

Creating a Client

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

To connect to a different Nuxeo Platform Instance, you can use the following:

nuxeo = Nuxeo(
  base_url='http://demo.nuxeo.com/nuxeo/',
  auth={
    'username': 'Administrator',
    'password': 'Administrator'
  })

Operation

Operation object allows you to execute an operation (or operation chain).

See the Operation documentation.

Samples

Call an operation to create a new folder in the Root document

operation = nuxeo.operation('Document.Create')
operation.params({
    'type': 'Folder',
    'name': 'My Folder',
    'properties': 'dc:title=My Folder \ndc:description=A Simple Folder'
  })
operation.input('/')
doc = operation.execute()

Request

The Request object allows you to call the Nuxeo REST API.

See the Request documentation.

Samples

Fetch the Administrator user

user = nuxeo.request('user/Administrator')

Fetch the whole list of Natures

natures = nuxeo.request('directory/nature')

Repository

The Repository object allows you to work with document.

See the Repository documentation.

Samples

Create a Repository object

defaultRepository = nuxeo.repository(); // 'default' repository
...
testRepository = nuxeo.repository('test'); // 'test' repository
...

Fetch the Root document

nuxeo.repository().fetch('/')

Create a new folder

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

Delete a document

nuxeo.repository().delete('/a-folder')

Document

Repository object returns and works with Document objects. Document objects exposes a simpler API to work with a document.

See the Document documentation.

Samples

Retrieve a Document object

doc = nuxeo.repository().fetch('/')

Set a document property

doc.set({ 'dc:title': 'foo' })

Get a document property

doc.get('dc:title')

Save an updated document

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

Fetch the main Blob of a document

doc.fetch_blob()

Convert a document main Blob to PDF

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

Fetch the 'thumbnail' rendition

doc.fetch_rendition('thumbnail')

Fetch the ACLs

doc.fetch_acls()

Add permission

doc.add_permission({'username': 'test', 'permission': 'Write'})

Remove permission

doc.remove_permission({'id': 'members:Write:true:Administrator::'})

Has permission

doc.has_permission('Write')

Lock document

doc.lock()

Unlock document

doc.unlock()

Fetch Lock Status

doc.fetch_lock_status()

Start a workflow

doc.start_workflow('SerialDocumentReview')

Complete a workflow task

task = workflow.fetch_tasks()
variables = {'participants':['user:Administrator'],'assignees':['user:Administrator'], 'end_date':'2011-10-23T12:00:00.00Z'};
task.complete('start_review', variables, comment='a comment');

BatchUpload

The BatchUpload object allows you to upload blobs to a Nuxeo Platform instance, and use them as operation input or as document property value.

See the BatchUpload documentation.

Samples

Create a Nuxeo.Blob to be uploaded

from nuxeo.blob import FileBlob
from nuxeo.blob import BufferBlob
BufferBlob('Content of this text', 'Test.txt', 'text/plain')
...
FileBlob('/path/to/file)

Upload a blob

nuxeo.batch_upload().upload(blob)

Attach an uploaded blob to a document

uploaded = nuxeo.batch_upload().upload(blob)
operation = nuxeo.operation('Blob.AttachOnDocument')
operation.params({'document':'/a-file'})
operation.input(uploaded)
operation.execute()

Users

The Users object allows you to work with users.

See the Users documentation.

Samples

Fetch an user

nuxeo.users().fetch('Administrator')

Create a new user

newUser = {
    'username': 'leela',
    'firstName': 'Leela',
    'company': 'Futurama',
    'email': '[email protected]',
  }
user = nuxeo.users().create(newUser)

Delete an user

nuxeo.users().delete('leela')

Groups

The Groups object allows you to work with groups.

See the Groups documentation.

Samples

Fetch a group

nuxeo.groups().fetch('administrators')

Create a new group

newGroup = {
  'groupname': 'foo',
  'grouplabel': 'Foo',
}
group = nuxeo.groups().create(newGroup)

Delete a group

nuxeo.groups().delete('foo')

Directory

The Directory object allows you to work with directories.

See the Directory documentation.

Samples

Fetch all entries of a directory

entries = nuxeo.directory('nature').fetchAll()

Fetch a given directory entry

entry = nuxeo.directory('nature').fetch('article')

Create a new directory entry

newEntry = {
  'id': 'foo',
  'label': 'Foo',
}
entry = nuxeo.directory('nature').create(newEntry)

Delete a directory entry

nuxeo.directory('nature').delete('foo')

Contributing

See our contribution documentation.

Requirements

Setup

Install Python and then use pip to install all the required libraries:

$ git clone https://github.com/nuxeo/nuxeo-python-client
$ cd nuxeo-python-client
$ pip install -r requirements.txt

Test

A Nuxeo Platform instance needs to be running on http://localhost:8080/nuxeo for the tests to be run.

Tests can be launched on Python Nosetests with:

$ nosetests -v

Tests can be launched without a server with Maven and Nosetests:

$ mvn -f ftest/pom.xml clean verify

Reporting Issues

You can follow the developments in the Nuxeo Python Client project of our JIRA bug tracker: https://jira.nuxeo.com/browse/NXPY.

You can report issues on answers.nuxeo.com.

License

Apache License 2.0 Copyright (c) Nuxeo SA

About Nuxeo

Nuxeo dramatically improves how content-based applications are built, managed and deployed, making customers more agile, innovative and successful. Nuxeo provides a next generation, enterprise ready platform for building traditional and cutting-edge content oriented applications. Combining a powerful application development environment with SaaS-based tools and a modular architecture, the Nuxeo Platform and Products provide clear business value to some of the most recognizable brands including Verizon, Electronic Arts, Sharp, FICO, the U.S. Navy, and Boeing. Nuxeo is headquartered in New York and Paris. More information is available at www.nuxeo.com.

8 months ago Remi Cattiau Review Python API
8 months ago Andrew Goodricke Add content-review-lts2016 to labels
8 months ago Kevin Leturc NXP-19481: Update MarkLogic page to detail how to configure range element indexes
a year ago Anne Jubert 16
3 years ago Solen Guitter 15 | fixed broken links to blog posts
4 years ago Solen Guitter 14
4 years ago Alain Escaffre 12
4 years ago Alain Escaffre 13
4 years ago Solen Guitter 11
4 years ago Solen Guitter 10
4 years ago Solen Guitter 9
5 years ago Olivier Grisel 7
5 years ago Olivier Grisel 8 | Migrated to Confluence 4.0
7 years ago Stéfane Fermigier 6
7 years ago Stéfane Fermigier 5
7 years ago Stéfane Fermigier 4
7 years ago Stéfane Fermigier 3
7 years ago Stéfane Fermigier 1
7 years ago Stéfane Fermigier 2
History: Created by Stéfane Fermigier