Admin API
pyPreservica 1.2 onwards now provides interfaces to the Administration and Management API
https://eu.preservica.com/api/admin/documentation.html
Note
Administration and Management API is a system management API for repository managers who have at least the role ROLE_SDB_MANAGER_USER
The Administration and Management API client is created using
from pyPreservica import *
client = AdminAPI()
Metadata Management (XSD Schema’s, XML Documents & XSLT Transforms)
Preservica holds XML metadata schema’s, XML templates and XSLT transforms, you can access the document stores programmatically via the admin API.
To list all the XML templates use
from pyPreservica import *
client = AdminAPI()
client.xml_documents()
This will return a list of dictionary objects containing the template attributes, e.g.
from pyPreservica import *
client = AdminAPI()
for doc in client.xml_documents():
print(doc['Name'])
You can access the XSD schema and XSLT templates in the same way
from pyPreservica import *
client = AdminAPI()
for schema in client.xml_schemas():
print(schema['Name'])
from pyPreservica import *
client = AdminAPI()
for transform in client.xml_transforms():
print(transform['Name'])
Individual xml documents can be requested via their namespace URI.
For example, to save a MODS xml template held in Preservica with a given URI to a local file, use:
from pyPreservica import *
client = AdminAPI()
with open("mods-template.xml", encoding="utf-8", mode="wt") as f:
f.write(client.xml_document("http://www.loc.gov/mods/v3"))
This now allows you to fetch a template from Preservica, update it and add it to a submission.
admin = AdminAPI()
dublin_core_template = admin.xml_document("http://www.openarchives.org/OAI/2.0/oai_dc/")
entity_response = xml.etree.ElementTree.fromstring(dublin_core_template)
entity_response.find(".//{http://purl.org/dc/elements/1.1/}title").text = "My Asset Title"
dublin_core_metadata = xml.etree.ElementTree.tostring(entity_response).decode("utf-8")
package = simple_asset_package(preservation_file="my-image.tiff",
Asset_Metadata={"http://www.openarchives.org/OAI/2.0/oai_dc/", dublin_core_metadata})
You can use similar code to fetch the XSD schema documents
from pyPreservica import *
client = AdminAPI()
with open("dublin-core.xsd", encoding="utf-8", mode="wt") as f:
f.write(client.xml_schema("http://purl.org/dc/elements/1.1/"))
To fetch a transform you need to provide both an input URI and output URI
from pyPreservica import *
client = AdminAPI()
with open("ead-cmis.xslt", encoding="utf-8", mode="wt") as f:
f.write(client.xml_transform("urn:isbn:1-931666-22-9", "http://www.w3.org/1999/xhtml"))
To add a new XML descriptive metadata template you can either pass an XML document held as a string or a file like object. If using a file, then make sure the file descriptor is opened in binary mode.
from pyPreservica import *
client = AdminAPI()
with open("my-template.xml", mode="rb") as f:
f.write(client.add_xml_document("my-template-name", f))
or via a string
from pyPreservica import *
client = AdminAPI()
client.add_xml_document("my-template-name", xml_document)
To delete an existing XML template use the URI identifier
from pyPreservica import *
client = AdminAPI()
client.delete_xml_document("http://purl.org/dc/elements/1.1/")
XSD Schema’s and XSLT Transforms can be added and deleted in a similar way
Using a file like object
from pyPreservica import *
client = AdminAPI()
with open("my-schema.xsd", mode="rb") as f:
f.write(client.add_xml_schema(name="my-schema", description="", originalName="my-schema.xsd", f))
or via a string
from pyPreservica import *
client = AdminAPI()
client.add_xml_schema(name="my-schema", description="", originalName="my-schema.xsd", xml_document)
and deletion is via the URI
from pyPreservica import *
client = AdminAPI()
client.delete_xml_schema("http://purl.org/dc/elements/1.1/")
User Management
List all the users within the tenancy by their username
from pyPreservica import *
client = AdminAPI()
for username in client.all_users():
print(username)
Fetch the full set of user details, such as full name, email address and roles
from pyPreservica import *
client = AdminAPI()
user = client.user_details(username):
print(user['FullName'])
print(user['Email'])
Create a CSV/Spreadsheet report containing details of all users within the tenancy, the report has the following columns, UserName, FullName, Email, Tenant, Enabled, Roles
from pyPreservica import *
client = AdminAPI()
client.user_report(report_name="users.csv")
Create new user accounts
from pyPreservica import *
client = AdminAPI()
username = "admin@example.com"
roles = ['SDB_MANAGER_USER', 'SDB_INGEST_USER']
user = client.add_user(username, full_name, roles)
Delete a user from the system
from pyPreservica import *
client = AdminAPI()
client.delete_user(username)
Change the display name of a user
from pyPreservica import *
client = AdminAPI()
client.change_user_display_name(username, "New Display Name")