
Overview
As IIIF Presentation API 3 becomes more widespread, I found it increasingly difficult to understand the specification and create JSON files directly.
So I tried using the following Python library, and this is a note for reference.
https://github.com/iiif-prezi/iiif-prezi3
I used this library for converting the data published on the Toji Hyakugo Monjo WEB to IIIF, as introduced in the following article.
The source code may be hard to read, but it is also published in the following repository, and I hope it is helpful.
https://github.com/nakamura196/toji_iiif
Creating a Collection
I was able to create an IIIF collection with the following code.
import iiif_prezi3
iiif_prezi3.config.configs['helpers.auto_fields.AutoLang'].auto_lang = "ja"
collection = iiif_prezi3.Collection(
id=f"{origin}/set/3/collection.json",
label="東寺百合文書",
viewingDirection="right-to-left",
provider=iiif_prezi3.ProviderItem(
id=self.homepage,
label=self.attribution,
),
homepage=iiif_prezi3.HomepageItem(
id=self.homepage,
type="Text",
label=self.attribution,
format="text/html",
language="ja"
),
metadata=[
iiif_prezi3.KeyValueString(label="Attribution", value=self.attribution),
iiif_prezi3.KeyValueString(label="Rights", value=self.rights),
],
rights=self.rights,
)
opath = f"{self.docs_dir}/iiif/set/3/collection.json"
os.makedirs(os.path.dirname(opath), exist_ok=True)
with open(opath, "w") as f:
f.write(collection.json(ensure_ascii=False, indent=2 if IS_DEBUG else None))
By setting iiif_prezi3.config.configs['helpers.auto_fields.AutoLang'].auto_lang to ja, the language field of label and metadata became ja.
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://nakamura196.github.io/toji_iiif/iiif/set/3/collection.json",
"type": "Collection",
"label": {
"ja": [
"東寺百合文書"
]
},
"metadata": [
{
"label": {
"ja": [
"Attribution"
]
},
"value": {
"ja": [
"京都府立京都学・歴彩館 東寺百合文書WEB"
]
}
},
{
"label": {
"ja": [
"Rights"
]
},
"value": {
"ja": [
"https://creativecommons.org/licenses/by/2.1/jp/"
]
}
}
],
"rights": "https://creativecommons.org/licenses/by/2.1/jp/",
"provider": [
{
"id": "https://hyakugo.pref.kyoto.lg.jp/",
"type": "Agent",
"label": {
"ja": [
"京都府立京都学・歴彩館 東寺百合文書WEB"
]
}
}
],
"homepage": [
{
"id": "https://hyakugo.pref.kyoto.lg.jp/",
"type": "Text",
"label": {
"ja": [
"京都府立京都学・歴彩館 東寺百合文書WEB"
]
},
"format": "text/html",
"language": [
"ja"
]
}
],
"items": [
{
"id": "https://nakamura196.github.io/toji_iiif/iiif/3/1/manifest.json",
"label": {
"ja": [
"イ函/1/:山城国紀伊郡司解案"
]
},
"type": "Manifest"
}
]
}
I also found it useful that using the iiif_prezi3.KeyValueString function outputs fields and values as arrays.
Additionally, providing iiif_prezi3.ProviderItem automatically sets "type": "Agent", which I think is an advantage of using the library.
Other Notes
Manifests and canvases could also be created in a similar manner.
In particular, the following was helpful for specifying canvas and image sizes.
https://iiif-prezi.github.io/iiif-prezi3/recipes/0004-canvas-size/
Summary
I hope this is helpful for using iiif-prezi3.