Skip to content

feat(client): add Tag entity (get, create, save, dispatch)#442

Merged
mekarpeles merged 1 commit into
masterfrom
impa/tag-entity
Jul 2, 2026
Merged

feat(client): add Tag entity (get, create, save, dispatch)#442
mekarpeles merged 1 commit into
masterfrom
impa/tag-entity

Conversation

@mekarpeles

Copy link
Copy Markdown
Member

Summary

Adds ol.Tag as a first-class entity in openlibrary-client, alongside ol.Work, ol.Edition, and ol.Author.

OL Tags are Infogami documents at /tags/OLnT introduced in GSoC 2023. They provide a controlled vocabulary for subject tagging.

New API

ol = OpenLibrary()

# Fetch by OLID
tag = ol.Tag.get('OL32T')
# → Tag(olid='OL32T', name='cooking', tag_type='subject', ...)

# Generic dispatch (works via the 'T' suffix)
tag = ol.get('OL32T')

# Save a change
tag.tag_description = "Updated description"
tag.save("update description")

# Create a new tag (requires auth + save_many)
ol.Tag.create('science_fiction', 'subject', 'Works of speculative fiction')

# Serialize to OL JSON
tag.json()
# → {'key': '/tags/OL32T', 'type': {'key': '/type/tag'}, 'name': 'cooking', ...}

What's included

  • ol.Tag property (dynamic class factory, same pattern as Work/Edition/Author)
  • Tag.get(olid) — fetches /tags/{olid}.json, returns None if not found
  • Tag.create(name, tag_type, description, comment) — via save_many
  • tag.save(comment)PUT /tags/{olid}.json
  • tag.json() — excludes read-only fields (olid, revision, latest_revision, created, last_modified), adds key and type
  • ol.get('OL32TÈ') dispatch via the T suffix
  • olclient/schemata/tag.schema.json — based on /type/tag and real OL documents

Testing

pytest tests/ -x -q
53 passed (7 new Tag tests)

New tests cover: Tag.__init__, tag.json(), Tag.get(), Tag.get() returns None for missing tags, ol.get() dispatch to Tag.

Related

Part of the openlibrary-client improvement series (PR 5 of 5):

Adds ol.Tag as a first-class entity alongside Work, Edition, Author:
- Tag.get(olid) — fetches /tags/{olid}.json, returns None if not found
- Tag.create(name, tag_type, description, comment) — via save_many
- tag.save(comment) — PUT /tags/{olid}.json
- tag.json() — serializes for OL API (excludes read-only fields)
- ol.get('OL32T') dispatches to Tag.get() via the 'T' suffix

Also adds olclient/schemata/tag.schema.json with the Tag document shape
based on /type/tag and real OL Tag documents (e.g. OL32T cooking).

7 new unit tests covering init, json(), get(), get-not-found, dispatch.
@mekarpeles
mekarpeles merged commit f056ce0 into master Jul 2, 2026
3 checks passed
@mekarpeles
mekarpeles deleted the impa/tag-entity branch July 2, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant