Add `ol tag add` to tag every work matching a set of subjects
@mekarpeles is already working on this.
Since Nov 21, 2026.
Assessment
This issue has not been assessed yet.
Description
Goal
Add one command to the ol CLI that tags every work matching a set of subjects:
ol tag add OL167T --subjects graphic_design,paintings,art_german
This adds the Tag /tags/OL167T to up to 100 works that have all of those subjects and don't have the Tag yet. Today this takes a hand-written script.
Command
ol tag add <TAG_OLID> --subjects <slug>[,<slug>...]
[--rm-subjects <slug>[,<slug>...]]
[--limit 100]
[--yes]
| Option | Meaning |
|---|---|
TAG_OLID |
The Tag to add, e.g. OL167T |
--subjects |
Subject slugs (as in /subjects/graphic_design), comma-separated, no spaces. A work must have all of them. |
--rm-subjects |
Subject slugs to remove from each tagged work. Default: remove nothing. |
--limit |
Maximum number of works to change. Default 100. |
--yes |
Save the changes. Without it, the command is a dry run that prints each change. |
How it works
- Log in with the credentials from
ol --configure. Print the account it will write as. - Resolve the Tag. Fetch
/tags/OL167T. Itstag_typedecides the work field:genre→genres,subgenre→subgenres, and so on. Refuse a Tag whose type has no work field. - Find works with
search.json, which matches subject slugs and supports AND and NOT:
subject_key:graphic_design AND subject_key:paintings AND subject_key:art_german AND -genre_key:OL167T, limited to--limit.
Infobase queries (query.json) can't AND two values of the same field, so use search here. - Fetch the works in one batch call and re-check each one: search can lag, so skip any work that already has the Tag. For
--rm-subjects, remove each subject string whose slug matches. - Save the batch with
/api/save_many, writing the Tag as a reference:"genres": [{"key": "/tags/OL167T"}]. Keep existing entries; only add.
Built from what exists
| Need | Existing piece | Work |
|---|---|---|
| Batch fetch | #440 get_many() |
Fix first. It sends a comma list to /api/get_many.json (production returns 500) and doesn't unwrap the {"status": "ok", "result": {...}} reply. The working form is /api/get_many?keys=<JSON array>. Its tests mock the wrong shapes and need fixing too. |
| Safe search queries | #454, URL-encoding search parameters | Merge |
| Tag type → work field | #457, explicit field map in Work.add_tags |
Reuse its map |
| Tag lookup | olclient/entity_helpers/tag.py (Tag.get) |
Use as is |
| Save | /api/save_many |
Add a small save_many() method |
No other repository or script is needed: Tags are live and queryable on openlibrary.org.
Done when
- #440 fixed and merged
-
ol tag addimplemented as anolsubcommand, dry run by default - Tests: subject slugs → search query; Tag type → field; already-tagged works skipped;
--rm-subjectsremoves only matching subjects; existing tags kept; dry run saves nothing - A
--limit 5dry run against openlibrary.org, output pasted in the PR - One small real run (
--limit 5 --yes) only after a maintainer approves it in the PR
Not in scope
- Replacing or removing Tags
- Reshaping the rest of
olinto subcommands - Query languages beyond
--subjects
- Dominant language
- Python
- Stars
- 509
- Forks
- 116
- Avg merge
- 11d 8h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from internetarchive/openlibrary-client
-
Add warning to readme about books creation not being possible.Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 62/100
-
ol batch: JSON batch/patch submission (create/add/submit) on the review-gated BookWorm pipelineOpen
Difficulty 5/5 Over a week Newbie friendliness 25/100
internetarchive/openlibrary-client#465 · 2 comments ·
-
CLI enhancement
Difficulty 4/5 Over a week Newbie friendliness 15/100
internetarchive/openlibrary-client#460 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
internetarchive/openlibrary-client#422 · 4 comments ·
All issues in internetarchive/openlibrary-client
Similar issues
-
[Bug]: streaming_end_of_stream_only guardrails rescan the whole stream on every chunk - blocks event loopPossibly taken A pull request linked to this issue is open or already merged. Openbug llm translation
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
arith ascend bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
tile-ai/tilelang#5173 · 2 comments · 1 reaction ·
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lanl/text-fetch#92 ·
Maintainers usually reply within 1 day
-
kind: for-triage
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
monumental-archive/.github#2284 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
TanbirRamim/open-source-radar#761 ·
Maintainers usually reply within 1 day