Flask-FedoraCommons is an extension to Flask that provides an interface to the open-source Fedora Commons digital repository. Certain modules from the Eulfedora project were forked and included as libraries in this extension.
Install the extension with one of the following commands:
$ easy_install Flask-FedoraCommons
or alternatively if you have pip installed:
$ pip install Flask-FedoraCommons
The fedora object itself can be used to configure the following required settings (and example values) for this extension:
FEDORA_ROOT | ‘http://fedora.host.name:8080/fedora/‘ |
FEDORA_USER | ‘user’ |
FEDORA_PASSWORD | ‘password’ |
FEDORA_PIDSPACE | ‘changeme’ |
FEDORA_TEST_ROOT | ‘http://fedora.host.name:8180/fedora/‘ |
FEDORA_TEST_PIDSPACE | ‘testme’ |
To get started with Flask-FedoraCommons, you need to instantiate a FedoraCommons object after configuring the application:
from flask import Flask
from flask_fedora_commons import FedoraCommons
app = Flask(__name__)
app.config.from_pyfile('mysettings.cfg')
fedora = FedoraCommons(app)
You can access both M-API and A-API REST web services available in the digital repository through the FedoraCommons API interface.
Class provides an interface to a Fedora Commons digital repository.
Returns a Repository object initializes with default configuration values
Method creates 1-n number of basic Fedora Objects in a repository
Parameters: |
|
---|---|
Rtype list: | List of PIDS |
Method takes a source_pid and collection_pid, retrives source_pid RELS-EXT and updates fedora:isMemberOfCollection value with new collection_pid
Parameters: |
|
---|---|
Rtype boolean: | True if move was a success |
Property method function returns or creates a class property for a Repository instance.
Teardown and closes the connection to a Repository instance
Parameters: | exception – Exception to catch during teardown |
---|
Pythonic interface to a single Fedora Commons repository instance. Based on Apache2 licensed source code from Emory University’s Eulfedora project
Given a DigitalObject, examine the object to select the most appropriate subclass to instantiate. This generic implementation examines the object’s content models and compares them against the defined subclasses of DigitalObject to pick the best match. Projects that have a more nuanced understanding of their particular objects should override this method in a Repository subclass. This method is intended primarily for use by infer_object_subtype().
Parameters: | obj – a DigitalObject to inspect |
---|---|
Return type: | a subclass of DigitalObject |
Default type to use for methods that return fedora objects - DigitalObject
Find objects in Fedora. Find query should be generated via keyword args, based on the fields in Fedora documentation. By default, the query uses a contains (~) search for all search terms. Calls ApiFacade.findObjects(). Results seem to return consistently in ascending PID order.
Example usage - search for all objects where the owner contains ‘jdoe’:
repository.find_objects(ownerId='jdoe')
Supports all search operators provided by Fedora findObjects query (exact, gt, gte, lt, lte, and contains). To specify the type of query for a particular search term, call find_objects like this:
repository.find_objects(ownerId__exact='lskywalker')
repository.find_objects(date__gt='20010302')
Parameters: |
|
---|---|
Return type: | generator for list of objects |
Request next available pid or pids from Fedora, optionally in a specified namespace. Calls ApiFacade.getNextPID().
Deprecated since version 0.14: Mint pids for new objects with eulfedora.models.DigitalObject.get_default_pid() instead, or call ApiFacade.getNextPID() directly.
Parameters: |
|
---|---|
Return type: | string or list of strings |
Initialize a single object from Fedora, or create a new one, with the same Fedora configuration and credentials.
Parameters: |
|
---|---|
Return type: | single object of the type specified |
Create: | boolean: create a new object? (if not specified, defaults to False when pid is specified, and True when it is not) |
Find objects in Fedora with the specified content model.
Parameters: |
|
---|---|
Return type: | list of objects |
Construct a DigitalObject or appropriate subclass, inferring the appropriate subtype using best_subtype_for_object(). Note that this method signature has been selected to match the DigitalObject constructor so that this method might be passed directly to get_object() as a type:
>>> obj = repo.get_object(pid, type=repo.infer_object_subtype)
See also: TypeInferringRepository
Ingest a new object into Fedora. Returns the pid of the new object on success. Calls ApiFacade.ingest().
Parameters: |
|
---|---|
Return type: | string |
Purge an object from Fedora. Calls ApiFacade.purgeObject().
Parameters: |
|
---|---|
Return type: | boolean |
instance of eulfedora.api.ResourceIndex, with the same root url and credentials
fields that can be searched against in find_objects()
human-readable aliases for oddly-named fedora search fields