Package: haufe.sharepoint
haufe.sharepointhaufe.sharepointallows to interact Python-based application with
Sharepointliststhrough the Sharepoint SOAP API (tested against
Microsoft Sharepoint Services 3.0).Featuresretrieve Sharepoint list definitionsretrieve all list itemsadd list itemsdelete list itemsupdate list itemsgeneric queriesauthentication over NTLMUsageIn order to connect to Sharepoint you need the following parametersthe Lists WSDL URLthe ID/Name of the related Sharepoint list you want to interact witha valid Sharepoint username and password (having the related rights)API usageConnecting to sharepointIn order to connect to Sharepoint you need to import theConnectormethod which is a factory return aListEndPointinstance:> from haufe.sharepoint import Connector
> url = 'http://sharepoint/bereiche/onlineschulungen/'
> username = 'YourDomain\\account'
> password = 'secret'
> list_id = '60e3f442-6faa-4b49-814d-2ce2ec88b8d5'
> service = Connector(url, username, password, list_id)Sharepoint list model introspectionThe internals of the list schema is available through themodelproperty
of theListEndPointinstance:> fields = service.modelThe primary key of the list is exposed through theprimary_keyproperty:> primary_key = service.primary_keyThe lists of all required field names and all fields is available through:> all_fields = service.all_fields
> required_fields = service.required_fieldsList item deletionIn order to delete list items by their primary key values, you can use
thedeleteItems()method:> result = service.deleteItems('54', '55')
> print result
> print result.result
> print result.okTheresultobject is an instance ofParsedSoapResultproviding a
flagok(True|False) indicating the overall success or overall failure
of the operation. The individual error codes are available by iterating over theresultproperty of theParsedSoapResultinstance.Updating list itemsYou can update existing list items by passing one or multiple dictionaries
toupdateItems(). Each dict must contain the value of the related primary key
(in this case theIDfield):> data = dict(ID='77', Title=u'Ruebennase', FirstName=u'Heinz')
> result = service.updateItems(data)
> print result
> print result.result
> print result.okupdateItems()will not raise any exception. Instead you need to
check theokproperty of the result object and if needed the individual
items of theresultproperty:# update an item (non-existing ID)
> data = dict(ID='77000', Title=u'Becker')
> result = service.updateItems(data)
> print result
> print result.result
> print result.okAdding items to a listTheaddItems()method works like theupdateItems()method
except that do not have pass in a primary key (since it is not known
on the client side). The assigned primary key value after adding
the item to the list should be available from theresultobject:> data = dict(Title=u'Ruebennase', FirstName=u'Heinz')
> result = service.addItems(data)
> print result
> print result.result
> print result.ok
> print 'assigned ID:', result.result[0]['row']._ows_IDRetrieving a single list itemgetItem()will return a single item by its primary key value:> data = service.getItem('77')Retrieving all list itemsgetItems()will return all list items (use with care!):> items = service.getItems()Generic query APIquery(**kw)can be used to query the list with arbitrary query parameters
where each subquery must perform an exact match. All subqueries are combined
using a logical AND:> items = service.query(FirstName='Heinz', Title='Becker')The result is returned a Python list of dictified list items.
All query parameters must represent a valid field name of the list (ValueError
exception raised otherwise).In order to perform a substring search across _all_ query parameter you may
pass themode='contains'parameter. To specify a prefix search across
all query parameters, usemode='beginswith'.View supporthaufe.sharepointsupports list views of Sharepoint. You can either
set a default view used for querying Sharepoint like:> service.setDefaultView('{D9DF14B-21F2-4D75-B796-EA74647C30C6'}')or you select the view on a per-query basis by passing the view name
asviewNamemethod parameter (applies togetItem(),getItems()andquery()):> items = service.getItems(viewName='{D9DF14B-21F2-4D75-B796-EA74647C30C6'}')Command line usagehaufe.sharepointcomes with a smallsharepoint-inspectorcommandline utility:sharepoint-inspector --url <URL> --list <LIST-ID-OR-NAME> --username <USERNAME> --password <PASSWORD> --cmd <CMD>where <CMD> is eitherfieldsoritemsRequirementsPython 2.4 or higher (no support for Python 3.X)Testedtested with Python 2.4-2.6suds 0.4.1 beta or checkout of the suds trunk (https://fedorahosted.org/suds/). suds 0.4.0 is _not_ sufficient!python-ntlm 1.0Microsoft Sharepoint Services 3.0 APIAuthorWritten for Haufe-Lexware GmbH, Freiburg, Germany.ZOPYX LimitedAndreas JungCharlottenstr. 37/1D-72070 Tuebingenwww.zopyx.cominfo@zopyx.comChangelog0.1.9 - 2011/06/03fixed some documentation glitchesadded logging at connection time0.1.8 - 2011/05/30fixed improper parameter usage in exception0.1.7 - 2011/05/24applied third-party patch containing minor fixes0.1.6 - 2011/05/04better connection error handlingWSDL url prefix automatically added to the Sharepoint URLfixed issue in getItems() with empty result sets0.1.5 - 2011/02/23added checkin_file(), checkout_file()the connectiontimeoutis now configurable through the Connector() APIadd setDefaultView() API0.1.4 - 2011/02/22support for exact|substring|prefix search through
the query() API0.1.3 - 2011/02/22added generic query() API0.1.2 - 2011/02/21implemented getItem() in a proper way0.1.1 - 2011/02/18minor fixesdocumentation updated0.1 - 2011/02/17Initial release