DSpace REST API Client Library

Overview

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 new REST API in DSpace that is used by its own user interface.

This library is a work in progress and so far offers basic create, update, retrieve functionality for Community, Collection, Bundle, Item and Bitstream objects.

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

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

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.

Example

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.

Install Requests, if not already installed: (use pyenv / virtualenv as you prefer!)

=2.5; python_version >= "3" Using cached idna-3.3-py3-none-any.whl (61 kB) Installing collected packages: urllib3, certifi, charset-normalizer, idna, requests Successfully installed certifi-2021.10.8 charset-normalizer-2.0.11 idna-3.3 requests-2.27.1 urllib3-1.26.8">
╰─$ pip install requests                           
Collecting requests
  Downloading requests-2.27.1-py2.py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 980 kB/s 
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.8-py2.py3-none-any.whl (138 kB)
     |████████████████████████████████| 138 kB 4.0 MB/s 
Collecting certifi>=2017.4.17
  Using cached certifi-2021.10.8-py2.py3-none-any.whl (149 kB)
Collecting charset-normalizer~=2.0.0; python_version >= "3"
  Downloading charset_normalizer-2.0.11-py3-none-any.whl (39 kB)
Collecting idna<4,>=2.5; python_version >= "3"
  Using cached idna-3.3-py3-none-any.whl (61 kB)
Installing collected packages: urllib3, certifi, charset-normalizer, idna, requests
Successfully installed certifi-2021.10.8 charset-normalizer-2.0.11 idna-3.3 requests-2.27.1 urllib3-1.26.8

Run the script:

╰─$ python example.py                                                                                                                                                                                                              1 ↵
Updating token to 9730dfb9-c4ea-4f56-a2f0-4dc4cacf5059
Authenticated successfully as [email protected]
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 @kshepherd for The Library Code GmbH with support from Universität Hohenheim

Comments
  • Small class, method changes

    Small class, method changes

    Various fixes:

    • Refactored class hierarchy for various DSpace Objects
    • Item will always call super __init__ even if passed empty data. This ensures new items won't accidentally use a class static metadata dict, and will have all members properly instantiated in DSpaceObject.__init__
    • update_dso made more stable and update_item updated to call it properly
    opened by kshepherd 0
  • Metadata manipulation

    Metadata manipulation

    Fixes to environment variable parsing (credentials, URLs) Fixes to GET and PATCH operations Inclusion of simple console.py runner to allow testing and use interactively within a Python 3 interactive environment New DSpaceObject.add_metadata() and DSpaceObject.clear_metadata() methods to help locally construct and edit DSOs

    opened by kshepherd 0
  • Replace print output with real logging

    Replace print output with real logging

    Right now, the dspace.py library prints errors, messages, and other output with simple print()s. This should be replaced with a proper configurable logger and the messages all given log levels.

    opened by kshepherd 0
  • DSpace client CLI interface

    DSpace client CLI interface

    We can add some CLI commands to the DSpace Python client that make it easier to explore and manipulate a DSpace repository via CLI or bash scripts. The initial idea here is to offer similar functionality like the kubectl command to explore a Kubernetes cluster. Some examples of how it could look like:

    • dspace-client login https://api7.dspace.org
      • Login to the specified DSpace instance
    • dspace-client get communities
      • List all communities
    • dspace-client get collections
      • List all collections
    • dspace-client metadata 12345/123
      • Display metadata by handle or uuid
    • dspace-client view item <uuid>
      • Display item related data by uuid
    • dspace-client download bitstream <uuid> -p <path>
      • Download bitstream to the specified path
    • dspace-client community <uuid>
      • Set current active community
    • dspace-client collection <uuid>
      • Set current active collection
    • dspace-client add item -f <path-to-json-file>
      • Add item to current active collection based file path or piping data
    • ...

    Of course any of the underlying command implementation can be imported into other Python scripts as well.

    I just wrote down things that popped up in my mind. Feel free to add or enhance commands.

    opened by tomdesair 1
  • Helper class methods for constructing resource metadata

    Helper class methods for constructing resource metadata

    At the moment, constructing an actual API resource object from scratch (eg. for creation) is mostly left up to the developer. It would be nice to have class methods for base DSO and if applicable, higher-level objects so that it is easy to add, update or otherwise manipulate a metadata value(s) (with field, value, language, authority, confidence as arguments) in a DSO that we're putting together in the python script. It could work something like

    item = new Item() item.add_metadata('dc.creator', 'Family-name, First-name', 'en') (authority=None, confidence=-1 defaults)

    Or, we could make item.metadata use a Metadata class and add methods to that like item.metadata.add(....) item.metadata.clear_by_field('dc.creator')

    And so on.

    enhancement 
    opened by kshepherd 0
Owner
The Library Code GmbH
DSpace Service Provider and Certified DSpace Partner
The Library Code GmbH
RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

RESTler is the first stateful REST API fuzzing tool for automatically testing cloud services through their REST APIs and finding security and reliability bugs in these services.

Microsoft 1.8k Jan 4, 2023
Django-rest-auth provides a set of REST API endpoints for Authentication and Registration

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)

Tivix 2.4k Dec 29, 2022
Little Library API REST

Little Library API REST py 3.10 The only one requeriment it's to have Flask installed.

Luis Quiñones Requelme 1 Dec 15, 2021
REST API framework designed for human beings

Eve Eve is an open source Python REST API framework designed for human beings. It allows to effortlessly build and deploy highly customizable, fully f

eve 6.6k Jan 4, 2023
Django REST API with React BoilerPlate

This is a setup of Authentication and Registration Integrated with React.js inside the Django Templates for web apps

Faisal Nazik 91 Dec 30, 2022
Estudo e desenvolvimento de uma API REST

Estudo e desenvolvimento de uma API REST ??‍?? Tecnologias Esse projeto utilizará as seguintes tecnologias: Git Python Flask DBeaver Vscode SQLite ??

Deusimar 7 May 30, 2022
Example Starlette REST API application

The idea of this project is to show how Starlette, Marshmallow, and SQLAlchemy can be combined to create a RESTful HTTP API application that is modular, lightweight, and capable of dealing with many simultaneous requests.

Robert Wikman 0 Jan 7, 2022
JSON:API support for Django REST framework

JSON:API and Django REST framework Overview JSON:API support for Django REST framework Documentation: https://django-rest-framework-json-api.readthedo

null 1k Dec 27, 2022
simple api build with django rest framework

Django Rest API django-rest-framework Employees management simple API in this project wrote test suites for endpoints wrote simple doc string for clas

OMAR.A 1 Mar 31, 2022
Simple Crud Api With Django Rest Framework

SIMPLE CRUD API WITH DJANGO REST FRAMEWORK Django REST framework is a powerful and flexible toolkit for building Web APIs. Requirements Python 3.6 Dja

kibet hillary 1 May 3, 2022
REST API with Flask. No data persistence.

Flask REST API Python 3.9.7 The Flask experience, without data persistence :D First, to install all dependencies: python -m pip install -r requirement

Luis Quiñones Requelme 1 Dec 15, 2021
BloodDonors: Built using Django REST Framework for the API backend and React for the frontend

BloodDonors By Daniel Yuan, Alex Tian, Aaron Pan, Jennifer Yuan As the pandemic raged, one of the side effects was an urgent shortage of blood donatio

Daniel Yuan 1 Oct 24, 2021
Build a Backend REST API with Python & Django

Build a Backend REST API with Python & Django Skills Python Django djangorestframework Aws Git Use the below Git commands in the Windows Command Promp

JeonSoohyun a.k.a Edoc.. 1 Jan 25, 2022
Simplified REST API to get stickers from Snap

Snap Sticker kit REST API Simplified REST API to get stickers from Snap ?? Instructions Search stickers Request: url = "https://sticker-kit-horizon733

Dishant Gandhi 1 Jan 5, 2022
Allows simplified Python interaction with Rapid7's InsightIDR REST API.

InsightIDR4Py Allows simplified Python interaction with Rapid7's InsightIDR REST API. InsightIDR4Py allows analysts to query log data from Rapid7 Insi

Micah Babinski 8 Sep 12, 2022
A small project in Python + Flask to demonstrate how to create a REST API

SmartBed-RESTApi-Example This application is an example of how to build a REST API. The application os a mock IoT device, simulating a Smart Bed. Impl

Rares Cristea 6 Jan 28, 2022
Flask RestAPI Project - Transimage Rest API For Python

[ 이미지 변환 플라스크 Rest API ver01 ] 0. Flask Rest API - in SunnyWeb : 이미지 변환 웹의 Flask

OliverKim 1 Jan 12, 2022
Eureka is a Rest-API framework scraper based on FastAPI for cleaning and organizing data, designed for the Eureka by Turing project of the National University of Colombia

Eureka is a Rest-API framework scraper based on FastAPI for cleaning and organizing data, designed for the Eureka by Turing project of the National University of Colombia

Julian Camilo Velandia 3 May 4, 2022