Skip to main content

A DSpace REST API client library

Project description

DSpace Python REST Client Library

This client library allows Python 3 scripts (Python 2 probably compatible but not officially supported) to interact with DSpace 7+ repositories, using the DSpace REST API.

This library is a work in progress and so far offers basic create, update, retrieve functionality for Community, Collection, Bundle, Item, Bitstream, Group and User (EPerson), and Resource Policy objects.

Help with extending the scope and improving the code is always welcome!

PyPI homepage: https://pypi.org/project/dspace-rest-client/

Requirements

  • Python 3.x (developed using Python 3.8.5)
  • Python Requests module (see requirements.txt)
  • Working DSpace 7 repository with an accessible REST API

Installation

To install with pip: pip install dspace_rest_client

(or pip3 or python -m pip as appropriate to your environment)

To install manually, clone this repository and install the requirements:

git clone https://github.com/the-library-code/dspace-rest-python.git
pip install -r requirements.txt

Usage

After installing dependencies, you're ready to run the script. You can either pass the base API URL to the DSpaceClient() constructor or set them as environment variables.

Some environment variables can be used when setting up the REST client connection. DSPACE_API_ENDPOINT is the base URL of your endpoint eg. http://localhost:8080/server DSPACE_API_USERNAME and DSPACE_API_PASSWORD are credentials to use for authentication.

See the example.py script for an example of community, collection, item, bundle and bitstream creation. Just set the credentials and base URL at the top of the script to match your test system, or if you've set environment variables, remove the arguments from the DSpaceClient() instantiation and the environment variables will be used as defaults.

The output from the example.py script should look something like:

╰─$ python example.py                                                                                                                                                                                                              1 ↵
Updating token to 9730dfb9-c4ea-4f56-a2f0-4dc4cacf5059
Authenticated successfully as kim@shepherd.nz
API Post: Updating token to b44f91c2-5386-4c11-a1ca-1ea06613fae4
{"timestamp":"2022-02-10T05:44:12.758+00:00","status":403,"error":"Forbidden","message":"Access is denied. Invalid CSRF token.","path":"/server/api/core/communities"}
API Post: Retrying request with updated CSRF token
community 31264734-49c0-4bff-8ed7-e09e3abbfe7a created successfully!
New community created! Handle: 123456789/10
collection c010ef9c-2483-47c3-83af-8a8c1f72e888 created successfully!
New collection created! Handle: 123456789/11
item e59dfc7a-f96e-4897-a913-e962b220132b created successfully!
New item created! Handle: 123456789/12
New bundle created! UUID: 528d1dd9-ca62-4609-bb2e-1ab367299447
New bitstream created! UUID: 4740048b-25fa-4040-b0d1-4b27f13de75d
All finished with example data creation. Visit your test repository to review created objects

Credits

Created by Kim Shepherd for The Library Code GmbH with support from Universität Hohenheim

License

This work is licensed under the BSD 3-Clause License

Copyright 2021 The Library Code GmbH

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

dspace_rest_client-0.1.17.tar.gz (32.4 kB view details)

Uploaded Source

Built Distribution

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

dspace_rest_client-0.1.17-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file dspace_rest_client-0.1.17.tar.gz.

File metadata

  • Download URL: dspace_rest_client-0.1.17.tar.gz
  • Upload date:
  • Size: 32.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for dspace_rest_client-0.1.17.tar.gz
Algorithm Hash digest
SHA256 6a4e91fdaab415a203a2450e7894c258e64fbbc9db128128c9f164528b9a2a46
MD5 1e8e6f6287a3e1fba483c32532d0c4d2
BLAKE2b-256 aa2bd23dc1619e223c8992a661654222a9f318ce08020c56b216160bbb12173f

See more details on using hashes here.

File details

Details for the file dspace_rest_client-0.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for dspace_rest_client-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 fdfbd25058f476225ff9e28c835a731b4787d916db429ae366c16a88eaa57028
MD5 7f84abd0f812f120e09ee04e64d3c51d
BLAKE2b-256 cd921c2c3cef024a288b4375da0d49761b8468c6def1a1fc814b133312621e48

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