[cvs] [Wiki] created: XmlRpcPythonHowTo

Wiki Guest wikiguest at horde.org
Tue Feb 27 01:43:14 PST 2007


guest [77.180.68.6]  Tue, 27 Feb 2007 01:43:14 -0800

Created page: http://wiki.horde.org/XmlRpcPythonHowTo

+ Using XML/RPC to interface with the Horde API using Python

You can easily use Python to communicate with Horde through XML/RPC. Recent versions of Python have a built-in library "xmlrpclib" which even supports SSL (the "https://" protocol) and authentication! Below you find an example which accesses Kronolith's API to enumerate and download calendars. You can do similar things with other Horde modules.

Look at the //modulename/lib/api.php// files in the Horde distribution to see which APIs you can use.

Note regarding SOAP: it is also possible to communicate with Horde's SOAP API using the Python library "SOAPpy", but the SOAP support in Horde does not seem to be fully complete (see the following ticket for more information: http://bugs.horde.org/ticket/?id=5046)

<code type="python">
# 
# Horde XML-RPC with Python Example
#
# This is a simple example which shows how to communicate with Horde through
# the XML-RPC interface using the Python programming language.
#
# It enumerates all calendars a user has read access to and saves them to
# the harddisk as VCALENDAR files for backup purposes.
#

import xmlrpclib

############################### User settings ###############################

# The user name on the Horde server. Use the _full_ email address here!
username = "user at my-server.com"

# The password of this Horde user
password = "secret"

# Protocol to use for connection ("http" or "https")
protocol = "https"

# Server host name
hostname = "horde.my-server.com"

############################## End of settings ##############################

url = "%s://%s:%s@%s/rpc.php" % (protocol, username, password, hostname)

print "Connecting to URL '%s'..." % url
server = xmlrpclib.ServerProxy(url, verbose=0)

print "Retrieving list of calendars..."

calendars = server.calendar.listCalendars(False, 4) # "read permission"

for calendarKey in calendars:
    print "Downloading calendar %s..." % calendarKey

    content = server.calendar.exportCalendar(calendarKey, "text/calendar")

    filename = calendarKey + ".ics"

    print "Writing file '%s'..." % filename

    f = file(filename, "wt")
    f.write(content.encode('utf-8'))
    f.close()

print "Done."
</code>



More information about the cvs mailing list