Documentation
Everything you can do in Arvest you can also do from code: Arvest is built on an open REST API. Use the Python package for scripts and notebooks, or call the API directly from any language. The examples below can be copied as they are; replace the email and password with your own.
01 Install
The package needs Python 3.9 or later. Install it straight from GitHub:
pip install git+https://github.com/ARVEST-APP/arvest-api.git02 Connect
Sign in with the email and password of your Arvest account. Keep them out of your code, for instance in environment variables.
import os
import arvestapi
ar = arvestapi.Arvest(
os.environ["ARVEST_EMAIL"],
os.environ["ARVEST_PASSWORD"],
)
print(f"Connected as {ar.profile.name}")03 Projects
List your projects, create one, rename it or remove it.
for project in ar.get_projects():
print(project.id, project.title)
project = ar.create_project(title="Rehearsal notes")
project.update_title("Rehearsal notes, week 2")
project.update_description("Videos and annotations from the second week.")
# project.remove()04 Media
Add images, videos, sound or documents, from your computer or from a link. Arvest gives each one an address you can use in manifests.
# from a file on your computer
photo = ar.add_media(path="photos/stage_plan.jpg")
# or from a link
video = ar.add_media(path="https://example.org/rehearsal.mp4")
print(photo.title, photo.get_full_url())
for media in ar.get_medias():
print(media.id, media.title)05 IIIF manifests
Bring in a IIIF manifest from a library or archive, or upload your own; then read and change its JSON.
manifest = ar.add_manifest(
path="https://iiif.bodleian.ox.ac.uk/iiif/manifest/e32a277e-91e2-4a6d-8ba6-cc4bad230410.json"
)
content = manifest.get_content()
content["label"] = {"en": ["Programme, 1978"]}
manifest.update_content(content)
print(manifest.get_full_url())06 Metadata
Each item has metadata in a format (Dublin Core by default). Read it, fill in fields, or define your own format.
media = ar.get_medias()[0]
print(media.get_metadata())
media.update_metadata({"creator": "Pina Bausch", "date": "1978"})
# a format of your own
fmt = ar.create_metadata_format("Rehearsals", [
{"term": "scene", "label": "Scene", "definition": "The scene shown."},
{"term": "take", "label": "Take", "definition": "Which take."},
])
media.update_metadata({"scene": "3", "take": "2"}, metadata_format=fmt)07 Export a workspace
A project's workspace (its documents, their places, groups, links and annotations) is one JSON document. Save it to analyse it elsewhere.
import json
project = next(p for p in ar.get_projects() if p.title == "Rehearsal notes")
with open("workspace.json", "w", encoding="utf-8") as f:
json.dump(project.user_workspace.to_dict(), f, ensure_ascii=False, indent=2)08 The REST API directly
Without the package: sign in at /auth/login to get a token, then send it as a Bearer header. Every endpoint is described in the Swagger reference.
import os
import requests
API = "https://api.arvest.app"
login = requests.post(f"{API}/auth/login", json={
"mail": os.environ["ARVEST_EMAIL"],
"password": os.environ["ARVEST_PASSWORD"],
})
login.raise_for_status()
headers = {"Authorization": f"Bearer {login.json()['access_token']}"}
profile = requests.get(f"{API}/auth/profile", headers=headers).json()
print(profile)TOKEN=$(curl -s -X POST https://api.arvest.app/auth/login \
-H "Content-Type: application/json" \
-d "{\"mail\": \"$ARVEST_EMAIL\", \"password\": \"$ARVEST_PASSWORD\"}" \
| python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
curl -s https://api.arvest.app/auth/profile -H "Authorization: Bearer $TOKEN"