A python wrapper for the CDStar API
Project description
# pycdstar
Python client library for CDStar
[](http://pycdstar.readthedocs.org/en/latest/?badge=latest)
[](https://travis-ci.org/clld/pycdstar)
[](http://codecov.io/github/clld/pycdstar?branch=master)
## Usage
```python
from pycdstar.api import Cdstar
# Initialize a client object, with connection info from a config file
cdstar = Cdstar()
# create a new object
obj = cdstar.get_object()
# with initially no associated metadata
assert obj.metadata is None
# assigning to the metadata property will create a metadata record
obj.metadata = {"creator": "pycdstar"}
# retrieve the now existing object
obj = cdstar.get_object(obj.id)
assert 'creator' in obj.metadata
# again, initially the bitstreams property is an empty list
assert not obj.bitstreams
# we add a bitstream by uploading a local file
bitstream = obj.add_bitstream(fname='README.txt')
# and re-read the object
obj.read()
# a bitstreams read method returns an iterator to allow for streaming,
# i.e. chunked downloads
assert ''.join(list(bitstream.read()))
assert len(obj.bitstreams) == 1
# to make sure the newly created resources are properly indexed, we allow
# for a short delay
sleep(1)
# now we search for a string we know to exist in the uploaded bitstream
res = cdstar.search('ssh')
assert len(res)
# the first element in the search results list has the bitstream as
# associated resource
assert 'ssh' in ''.join(list(res[0].resource.read()))
query = 'pycdstar'
res = cdstar.search(query, index='metadata')
assert len(res)
res = cdstar.search(query, index='fulltext')
assert not len(res)
bitstream.delete()
obj.delete()
```
Python client library for CDStar
[](http://pycdstar.readthedocs.org/en/latest/?badge=latest)
[](https://travis-ci.org/clld/pycdstar)
[](http://codecov.io/github/clld/pycdstar?branch=master)
## Usage
```python
from pycdstar.api import Cdstar
# Initialize a client object, with connection info from a config file
cdstar = Cdstar()
# create a new object
obj = cdstar.get_object()
# with initially no associated metadata
assert obj.metadata is None
# assigning to the metadata property will create a metadata record
obj.metadata = {"creator": "pycdstar"}
# retrieve the now existing object
obj = cdstar.get_object(obj.id)
assert 'creator' in obj.metadata
# again, initially the bitstreams property is an empty list
assert not obj.bitstreams
# we add a bitstream by uploading a local file
bitstream = obj.add_bitstream(fname='README.txt')
# and re-read the object
obj.read()
# a bitstreams read method returns an iterator to allow for streaming,
# i.e. chunked downloads
assert ''.join(list(bitstream.read()))
assert len(obj.bitstreams) == 1
# to make sure the newly created resources are properly indexed, we allow
# for a short delay
sleep(1)
# now we search for a string we know to exist in the uploaded bitstream
res = cdstar.search('ssh')
assert len(res)
# the first element in the search results list has the bitstream as
# associated resource
assert 'ssh' in ''.join(list(res[0].resource.read()))
query = 'pycdstar'
res = cdstar.search(query, index='metadata')
assert len(res)
res = cdstar.search(query, index='fulltext')
assert not len(res)
bitstream.delete()
obj.delete()
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycdstar-0.1.1.tar.gz
(14.4 kB
view details)
File details
Details for the file pycdstar-0.1.1.tar.gz.
File metadata
- Download URL: pycdstar-0.1.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dad3be5a0b2276c8e7607eae853eeca93581bc85cd9d74a0d429042206641ac3
|
|
| MD5 |
3dfbe1342aa8e7c406fd1ec85f40bdc8
|
|
| BLAKE2b-256 |
56f2aa0c1b3fa403ceed96288dcd70d4adf2a62622f960a11410f1bc0f2ac127
|