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 adatetime
object.
Exceptions¶
Main object¶
-
class
dokuwiki.
DokuWiki
(url, user, password, **kwargs)[source]¶ Initialize a connection to a DokuWiki wiki.
url
,user
andpassword
are respectively the URL, the login and the password for connecting to the wiki.kwargs
arexmlrpclib
/xmlrpc.client
ServerProxy parameters.The exception
DokuWikiError
is raised if the authentication fails but others exceptions (likesocket.gaierror
for invalid domain,xmlrpc.client.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)
Note
The URL format is:
PROTO://FQDN[/PATH]
(https://www.example.com/dokuwiki for example).To use cookie based authentication (use HTTP cookies instead of passing login and password in the URI), set
cookieAuth
parameter to True:wiki = dokuwiki.DokuWiki('URL', 'USER', 'PASSWORD', cookieAuth=True)
-
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.
-
xmlrpc_version
[source]¶ 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
.
-
login
(user, password)[source]¶ Log to the wiki using user and password credentials. It returns a boolean that indicates if the user succesfully authenticate.
-
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 anDokuWiki
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())
-
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.
-
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 anDokuWiki
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, b64decode=False)[source]¶ Returns the binary data of media or save it to a file. If dirpath is not set the binary data is returned, otherwise the data is 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.
-
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.
-