dspace Module

class dspace.DSpace(public_key, private_key, rest_path)[source]

DSpace provides methods for interacting with the DSpaceTools API, which is a custom REST API for the ASU Digital HPS Repository.

Methods

all_collections() Retrieves details about all of the collections to which a user has access.
bitstream(bitstream) Returns information about a bitstream.
clean_text(s) Gets rid of garbage.
collection(collection) Retrieves details for a specific collection, by id.
communities() Retrieves all of the communities to which the user has access.
community(community) Retrieves details about a specific community, by id.
dict_from_node(node[, recursive]) Converts ElementTree node to a dictionary.
get_bitstream(bitstream[, save_path]) Downloads a bitstream and handles it.
get_digest(path) Produces an authentication digest based on resource path and your private key.
get_element_from_resource(path[, idOnly]) Retrieves the desired resource from the DSpace API.
get_path(path[, idOnly]) Produces a full path for the desired resource.
item(item) Retrieve an item by id.
item_metadata(item) Returs metadata for an item as a simple dictionary, with dc fields as keys.
list_bitstream_ids(item) Returns a list of bitstream ids for an item.
list_collection_ids(community) Returns a list of collection IDs for a given community.
list_collections(community) Retrieves details about the collections in a community.
list_item_ids(collection) Returns a list of item IDs for a given collection.
list_items(collection) Retrieves details about all items in a collection.
all_collections()[source]

Retrieves details about all of the collections to which a user has access.

Returns :list : a list of nested dictionaries.
bitstream(bitstream)[source]

Returns information about a bitstream.

Parameters :

item : string or int

An item id.

Returns :

dict : a nested dictionary.

clean_text(s)[source]

Gets rid of garbage. Strips non-ascii characters, newlines, and leading/ trailing whitespace.

Parameters :

s : string

A messy string.

Returns :

string : a somewhat cleaner string.

collection(collection)[source]

Retrieves details for a specific collection, by id.

Parameters :

collection : string or int

Collection id.

Returns :

dict : a nested dictionary.

communities()[source]

Retrieves all of the communities to which the user has access.

Returns :list : a list of nested dictionaries.
community(community)[source]

Retrieves details about a specific community, by id.

Parameters :

community : string or int

Community id.

Returns :

dict : a nested dictionary.

dict_from_node(node, recursive=False)[source]

Converts ElementTree node to a dictionary.

Parameters :

node : ElementTree node

recursive : boolean

If recursive=False, the value of any field with children will be the number of children.

Returns :

dict : nested dictionary.

Tags as keys and values as values. Sub-elements that occur multiple times in an element are contained in a list.

get_bitstream(bitstream, save_path=None)[source]

Downloads a bitstream and handles it. If save_path is provided, returns a file pointer. Otherwise returns the content of the bitstream.

Parameters :

bitstream : string or int

A bitstream id.

save_path : string or None

Full path where bitstream should be saved, including the filename.

Returns :

Contents of bitstream, or file pointer. :

Notes

WARNING: This has only been tested on bitstreams containing text data!

TODO: More robust handling for different data types.

get_digest(path)[source]

Produces an authentication digest based on resource path and your private key.

Parameters :

path : string

Relative URL of desired resource. E.g. ‘/items.xml’

Returns :

string : authentication digest for desired resource.

get_element_from_resource(path, idOnly=False)[source]

Retrieves the desired resource from the DSpace API.

Parameters :

path : string

Relative URL of desired resource. E.g. ‘/items.xml’

idOnly : boolean

If True, will yield only id/reference information for the desired resource. Default is False.

Returns :

ElementTree node : containing API response.

get_path(path, idOnly=False)[source]

Produces a full path for the desired resource.

Parameters :

path : string

Relative URL of desired resource. E.g. ‘/items.xml’

idOnly : boolean

If True, the returned path will yield only id/reference information for the desired resource. Default is False.

Returns :

string : full URL of desired resource, including authentication

information.

item(item)[source]

Retrieve an item by id.

Parameters :

item : string or int

An item id.

Returns :

dict : a nested dictionary.

item_metadata(item)[source]

Returs metadata for an item as a simple dictionary, with dc fields as keys.

Parameters :

item : string or int

An item id.

Returns :

dict : metadata, with dc fields as keys.

list_bitstream_ids(item)[source]

Returns a list of bitstream ids for an item.

Parameters :

item : string or int

An item id.

Returns :

list : a list of bitstream ids.

list_collection_ids(community)[source]

Returns a list of collection IDs for a given community.

Parameters :

community : string or int

Community id.

Returns :

list : a list of collection ids.

list_collections(community)[source]

Retrieves details about the collections in a community.

Parameters :

community : string or int

Community id.

Returns :

list : a list of nested dictionaries.

list_item_ids(collection)[source]

Returns a list of item IDs for a given collection.

Parameters :

collection : string or int

Collection id.

Returns :

list : a list of item ids.

list_items(collection)[source]

Retrieves details about all items in a collection.

Parameters :

collection : string or int

Collection id.

Returns :

list : a list of nested dictionaries.

Previous topic

Welcome to the DSPace Custom API Methods documentation!

This Page