Skip to main content

A python wrapper for the CDStar API

Project description

pycdstar

Python client library for CDStar

Build Status PyPI codecov.io

Usage

    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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycdstar-1.0.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycdstar-1.0.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file pycdstar-1.0.1.tar.gz.

File metadata

  • Download URL: pycdstar-1.0.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.12.3 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.2

File hashes

Hashes for pycdstar-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0ccdfd44a6b2681de72df9a949994cc6d0985c105ac2d126cee2428ab878308e
MD5 f451f4ef69c465d49a98245355915a61
BLAKE2b-256 c2caac24c20451c35fd0045fb933a4ac51f73098931442734317b5e022aa7a1e

See more details on using hashes here.

File details

Details for the file pycdstar-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pycdstar-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.12.3 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.5.2

File hashes

Hashes for pycdstar-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c8162b7cdc2406fc1119e7c5247bc96bc84e14f7da13368f85aab413ab7f3ad2
MD5 eccc824d50921f8c4612b928a2b189aa
BLAKE2b-256 e0bd02bf30fa2f627ff6aed6bffc64553d7052273b703f1cf5072b9976c3b48f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page