python-dokuwiki documentation

This python module aims to manage DokuWiki wikis by using the provided XML-RPC API. It is compatible with python2.7 and python3+.

Installation

It is on PyPi so you can use the pip command to install it:

pip install dokuwiki

Otherwise sources are in github

API

Functions

dokuwiki.date(date)[source]

DokuWiki returns dates of xmlrpclib/xmlrpc.client DateTime type and the format changes between DokuWiki versions ... This function convert date to a datetime object.

dokuwiki.utc2local(date)[source]

DokuWiki returns date with a +0000 timezone. This function convert date to the local time.

Exceptions

class dokuwiki.DokuWikiError[source]

Exception raised by this module when there is an error.

Main object

class dokuwiki.DokuWiki(url, user, password, **kwargs)[source]

Initialize a connection to a DokuWiki wiki. url, user and password are respectively the URL, the login and the password for connecting to the wiki. kwargs are xmlrpclib/xmlrpc.client ServerProxy parameters.

The exception DokuWikiError is raised if the authentification fails but others exceptions (like gaierror for invalid domain, ProtocolError for an invalid wiki, ...) are not catched.

try:
    wiki = dokuwiki.DokuWiki('URL', 'USER', 'PASSWORD')
except (DokuWikiError, Exception) as err:
    print('unable to connect: %s' % err)
send(command, *args, **kwargs)[source]

Generic method for executing an XML-RPC command. args and kwargs are the arguments and parameters needed by the command.

version

Property that returns the DokuWiki version of the remote Wiki.

time

Property that returns the current time at the remote wiki server as Unix timestamp.

xmlrpc_version

Property that returns the XML RPC interface version of the remote Wiki. This is DokuWiki implementation specific and independent of the supported standard API version returned by wiki.getRPCVersionSupported.

xmlrpc_supported_version

Property that returns 2 with the supported RPC API version.

title

Property that returns the title of the wiki.

login(user, password)[source]

Log to the wiki using user and password credentials. It returns a boolean that indicates if the user succesfully authenticate.

add_acl(scope, user, permission)[source]

Add an ACL rule that restricts the page/namespace scope to user (use @group syntax for groups) with permission level. It returns a boolean that indicate if the rule was correctly added.

del_acl(scope, user)[source]

Delete any ACL matching the given scope and user (or group if @group syntax is used). It returns a boolean that indicate if the rule was correctly removed.

Pages

class dokuwiki._Pages(dokuwiki)[source]

This object regroup methods for managing pages of a DokuWiki. This object is accessible from the pages property of an DokuWiki instance:

wiki = dokuwiki.DokuWiki('URL', 'User', 'Password')
wiki.pages.list()
list(namespace='/', **options)[source]

List all pages of the given namespace.

Valid options are:

  • depth: (int) recursion level, 0 for all
  • hash: (bool) do an md5 sum of content
  • skipacl: (bool) list everything regardless of ACL
changes(timestamp)[source]

Returns a list of changes since given timestamp.

For example, for returning all changes since 2016-01-01:

from datetime import datetime
wiki.pages.changes(datetime(2016, 1, 1).timestamp())
search(string)[source]

Performs a fulltext search on string and returns the first 15 results.

versions(page, offset=0)[source]

Returns the available versions of page. offset can be used to list earlier versions in the history.

info(page, version=None)[source]

Returns informations of page. Informations of the last version is returned if version is not set.

get(page, version=None)[source]

Returns the content of page. The content of the last version is returned if version is not set.

append(page, content, **options)[source]

Appends content text to page.

Valid options are:

  • sum: (str) change summary
  • minor: (bool) whether this is a minor change
html(page, version=None)[source]

Returns HTML content of page. The HTML content of the last version of the page is returned if version is not set.

set(page, content, **options)[source]

Set/replace the content of page.

Valid options are:

  • sum: (str) change summary
  • minor: (bool) whether this is a minor change
delete(page)[source]

Delete page by setting an empty content.

lock(page)[source]

Locks page.

unlock(page)[source]

Unlocks page.

permission(page)[source]

Returns the permission level of page.

Returns a list of all links contained in page.

Returns a list of all links referencing page.

Medias

class dokuwiki._Medias(dokuwiki)[source]

This object regroup methods for managing medias of a DokuWiki. This object is accessible from the medias property of an DokuWiki instance:

wiki = dokuwiki.DokuWiki('URL', 'User', 'Password')
wiki.medias.list()
list(namespace='/', **options)[source]

Returns all medias of the given namespace.

Valid options are:

  • depth: (int) recursion level, 0 for all
  • skipacl: (bool) skip acl checking
  • pattern: (str) check given pattern
  • hash: (bool) add hashes to result list
changes(timestamp)[source]

Returns the list of medias changed since given timestamp.

For example, for returning all changes since 2016-01-01:

from datetime import datetime
wiki.medias.changes(datetime(2016, 1, 1).timestamp())
get(media, dirpath=None, filename=None, overwrite=False)[source]

Returns the binary datas of media or save it to a file. If dirpath is not set the binary datas are returned, otherwise the datas are saved to a file. By default, the filename is the name of the media but it can be changed with filename parameter. overwrite parameter allow to overwrite the file if it already exists locally.

info(media)[source]

Returns informations of media.

add(media, filepath, overwrite=True)[source]

Set media from local file filepath. overwrite parameter specify if the media must be overwrite if it exists remotely.

set(media, _bytes, overwrite=True)[source]

Set media from _bytes. overwrite parameter specify if the media must be overwrite if it exists remotely.

delete(media)[source]

Delete media.

Dataentries

class dokuwiki.Dataentry[source]

Object that manage data entries.

static get(content, keep_order=False)[source]

Get dataentry from content. keep_order indicates whether to return an ordered dictionnay.

static gen(name, datas)[source]

Generate dataentry name from datas.

static ignore(content)[source]

Remove dataentry from content.