cdstar api的python包装器
pycdstar的Python项目详细描述
PycdStar
用于cdstar的python客户端库
用法
frompycdstar.apiimportCdstar# Initialize a client object, with connection info from a config filecdstar=Cdstar()# create a new objectobj=cdstar.get_object()# with initially no associated metadataassertobj.metadataisNone# assigning to the metadata property will create a metadata recordobj.metadata={"creator":"pycdstar"}# retrieve the now existing objectobj=cdstar.get_object(obj.id)assert'creator'inobj.metadata# again, initially the bitstreams property is an empty listassertnotobj.bitstreams# we add a bitstream by uploading a local filebitstream=obj.add_bitstream(fname='README.txt')# and re-read the objectobj.read()# a bitstreams read method returns an iterator to allow for streaming,# i.e. chunked downloadsassert''.join(list(bitstream.read()))assertlen(obj.bitstreams)==1# to make sure the newly created resources are properly indexed, we allow# for a short delaysleep(1)# now we search for a string we know to exist in the uploaded bitstreamres=cdstar.search('ssh')assertlen(res)# the first element in the search results list has the bitstream as# associated resourceassert'ssh'in''.join(list(res[0].resource.read()))query='pycdstar'res=cdstar.search(query,index='metadata')assertlen(res)res=cdstar.search(query,index='fulltext')assertnotlen(res)bitstream.delete()obj.delete()