Simplifies interaction with the WorldCat API.
Project description
WorldCat Client
The WorldCat Client library for Python provides a simplified way to interact with the WorldCat API and includes support for authentication and session handling, as well as the querying and parsing of certain data sets held in WorldCat.
Requirements
The WorldCat Client library has been tested with Python 3.10, 3.11, 3.12, 3.13 and 3.14. The library was not designed to work with Python 3.9 or earlier.
Installation
The WorldCat Client library is available from the PyPi repository, so may be added to a project's dependencies via its requirements.txt file or similar by referencing the WorldCat Client library's name, worldcatclient, or the library may be installed directly onto your local development system using pip install by entering the following command:
$ pip install worldcatclient
Usage
The WorldCat Client library provides the WorldCatClient class which can be used to interact
with the supported WorldCat API services.
The instantiation of the client is very simple. The examples shown below in the Client Instantiation & Setup section show the basic instantiation of the WorldCat Client, and also some basic error handling, highlighting the different custom exceptions supported by the client.
Client Methods
The the following methods are provided by the client:
-
search(...)(Iterator[dict[str, object]]|Iterator[WorldCatRecord]) – this method is used to search via the WorldCat Search API for brief bibliographic records, and yields the record results through an iterator. The method accepts the following keyword arguments:query(str) – (required) use to specify the search query.limit(int) – (optional) used to specify the maximum number of search results to obtain per API call; defaults to10; if specified must have a value between1–50results.maximum(int) – (optional) used to specify the maximum number of search results to obtain in total; defaults to50; if specified must have a value between1–10000results. If themaximumis less than thelimit, thelimitwill be lowered to match themaximumfor efficiency by preventing unused records from being requested.parsed(bool) – (optional) use to control whether the.search()method returns raw dictionary record payloads or parsed record payload asWorldCatRecordclass instances; defaults toFalse, set toTrueto return parsed record payloads.order(WorldCatOrderingSearchAPI) – (optional) use to specify the sort order for the search results; defaults toWorldCatOrderingSearchAPI.BestMatch, but can be set to any of the availableWorldCatOrderingSearchAPIenumeration options. See Sort Order section below.timeout(int) – (optional) used to specify the maximum timeout for the API call; defaults to10seconds; if specified must have a value between1–120seconds.offset(int) – (optional) used internally by the method to support paginating through the results; defaults toNone; if specified must have a value of1or greater; must not be specified manually.
Client Initialisation & Setup
The example illustrates initialising the WorldCatClient by providing the required parameters, then demonstrates use of the various methods of the client to perform the supported operations:
from worldcatclient import WorldCatClient
# Initialise client with the client ID, token, and any desired optional parameters:
client = WorldCatClient(
client_id = "<token>",
secret = "<secret>",
)
# Query the WorldCat API and do something with the results:
for record in client.search(query="ti:WorldCat API"):
assert isinstance(record, dict)
print(record)
Records
The WorldCat Client can return search results in two forms: as dictionary instances, which hold the raw search result record payloads, or as instances of the library's WorldCatRecord class which simplifies the process of interacting with the search results by parsing the raw payloads into class instances that provide properties to access each value.
To perform a search and to have the WorldCatClient return WorldCatRecord class
instances instead of dictionaries holding the raw search result record payloads, simply pass the optional parsed argument to the .search() method with a value of True:
from worldcatclient import WorldCatClient, WorldCatRecord
client = WorldCatClient(
client_id = "<token>",
secret = "<secret>",
)
# Query the WorldCat API and do something with the results:
for record in client.search(query="ti:WorldCat API", parsed=True):
assert isinstance(record, WorldCatRecord)
print(record)
print(record.title)
print(record.creator)
print(record.oclc_number)
The WorldCatRecord class instances offer the following properties to access the parsed
search result record data:
oclc_number– provides access to the publication's OCLC record number;title– provides access to the publication's title;creator– provides access to the publication's creator;machine_readable_date– provides access to the publication's date in machine-readable form;language– provides access to the publication's language;general_format– provides access to the publication's general format, such as 'Book';specific_format– provides access to the publication's specific format, such as 'eBook';publisher– provides access to the publication's publisher;publication_place– provides access to the publication's place of publication;isbns– provides access to the publication's list of associated ISBNs, if any;cataloging_info– provides access to the publication's cataloging information, if specified, which is returned as an instance of theWorldCatInfoclass (see below) orNoneotherwise.
The WorldCatInfo class instances, accessible via the WorldCatRecord class' cataloging_info property, provides access to the following cataloging fields:
cataloging_agency– provides access to the name of the agency that cataloged the publication within the parent search result;cataloging_language– provides access to the name of the language of the cataloging for the publication within the parent search result;level_of_cataloging– provides access to the level of cataloging for the publication, if any, within the parent search result;transcribing_agency– provides access to the name of the agency that transcribed the publication's cataloging information, if any, within the parent search result.
Search Results Sort Order
The sort order of the search results can be modified from their default sort order of
"best match", by specifying the order keyword argument when calling the .search()
method, and specifying one of the available WorldCatOrderingSearchAPI enumeration
options. The available options are as follows:
| Enumeration Option | Description |
|---|---|
Library |
Sort by library |
Recency |
Sort by recency |
BestMatch |
Sort by best match (the default) |
Creator |
Sort by creator |
PublicationDateAsc |
Sort by publication date (ascending) |
PublicationDateDesc |
Sort by publication date (descending) |
MostWidelyHeld |
Sort by most widely held |
Title |
Sort by most title |
For example to search and sort by recency, the .search() method would be called as
shown below:
from worldcatclient import WorldCatClient, WorldCatRecord, WorldCatOrderingSearchAPI
client = WorldCatClient(
client_id = "<token>",
secret = "<secret>",
)
# Query the WorldCat API and do something with the results:
for record in client.search(
query="ti:WorldCat API",
order=WorldCatOrderingSearchAPI.Recency,
parsed=True,
):
assert isinstance(record, WorldCatRecord)
print(record)
Code Formatting
The WorldCat Client library adheres to the code formatting specifications set out in PEP-8, which are verified and applied by the Black code formatting tool. Whenever code changes are made to the library, one needs to ensure that the code conforms to these code formatting specifications. To simplify this, the provided Dockerfile creates an image that supports running the Black code formatting tool against the latest version of the code, and will report back if any issues are found. To run the code formatting checks, perform the following commands, which will build the Docker image via docker compose build and then run the tests via docker compose run black – the output of running the formatting checks will be displayed:
$ docker compose build
$ docker compose run black
If any code formatting issues are found, it is possible to run Black so that it will automatically reformat the affected files; this can be achieved as follows:
$ docker compose run black --reformat
The above will reformat any files that contained code formatting issues, and will report back on what changes were made; once the code has been automatically reformatted, it will continue to pass the formatting checks until any future code changes that fall outside of the PEP-8 and Black code formatting specifications.
Code Linting
The WorldCat Client library adheres to the code linting specifications set out in PEP-8, which are verified and applied by the PyFlakes code linting tool. Whenever code changes are made to the library, one needs to ensure that the code conforms to these code formatting specifications. To simplify this, the provided Dockerfile creates an image that supports running the PyFlakes code linting tool against the latest version of the code, and will report back if any issues are found. To run the code linting checks, perform the following commands, which will build the Docker image via docker compose build and then run the tests via docker compose run flakes – the output of running the linting checks will be displayed:
$ docker compose build
$ docker compose run flakes
If any code linting issues are found, such as references to undefined names, or unused imports, each issue will need to be addressed by making the necessary code changes and re-testing with PyFlakes, before the library changes can be submitted for review.
Unit Tests
The WorldCat Client library includes a suite of comprehensive unit tests which ensure that the library functionality operates as expected, including testing and validating client instantiation, entry retrieval, creation, updating, publishing, un-publishing, and deletion. The unit tests were developed with and run via pytest.
To ensure that the unit tests are run within a predictable runtime environment where all of the necessary dependencies are available, a Docker image is created within which the tests are run. To run the unit tests, perform the following commands, which will build the Docker image via docker compose build and then run the tests via docker compose run tests – the output of running the tests will be displayed:
$ docker compose build
$ docker compose run tests
To run the unit tests with optional command line arguments being passed to pytest, append the relevant arguments to the docker compose run tests command, as follows, for example passing -vv to enable verbose output:
$ docker compose run tests -vv
It is also possible to view additional output from the test suite by running the tests with the -s command line flag, which captures standard output from any running code and emits it into the terminal for review.
$ docker compose run tests -vv -s
Additionally, if you wish to just run a single unit test, say for a new feature being developed, the -k command line flag can be used to filter the unit tests that will be run, where you can specify a range of values to the option, including the name of the unit test function or file that you want to use:
$ docker compose run tests -vv -s -k test_client_initialisation
See the documentation for PyTest regarding available optional command line arguments.
Copyright & License Information
Copyright © 2026 Daniel Sissman; licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file worldcatclient-0.8.5.tar.gz.
File metadata
- Download URL: worldcatclient-0.8.5.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c55339bbacdc1a9db1dc5b2f9a24d7a8f804de94835f27b730c3577ed37b0108
|
|
| MD5 |
a7198e0e69dd0182cbc20f9ed1929d02
|
|
| BLAKE2b-256 |
54f17c9be275fcb180dea0c9288d9db3c15d386d19b90c728a721718006b3bab
|
Provenance
The following attestation bundles were made for worldcatclient-0.8.5.tar.gz:
Publisher:
python-publish.yml on bluebinary/worldcat-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
worldcatclient-0.8.5.tar.gz -
Subject digest:
c55339bbacdc1a9db1dc5b2f9a24d7a8f804de94835f27b730c3577ed37b0108 - Sigstore transparency entry: 1775957728
- Sigstore integration time:
-
Permalink:
bluebinary/worldcat-client@4a55d4a1eda39b860cf0372c8771859beec6b4dc -
Branch / Tag:
refs/tags/v0.8.5 - Owner: https://github.com/bluebinary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4a55d4a1eda39b860cf0372c8771859beec6b4dc -
Trigger Event:
release
-
Statement type:
File details
Details for the file worldcatclient-0.8.5-py3-none-any.whl.
File metadata
- Download URL: worldcatclient-0.8.5-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
696852baf5f587f2d5c9306de28dc5809defeca3f469bd92a3c24981363cf7d0
|
|
| MD5 |
2231ee0a965cc885d120df14a78f4e71
|
|
| BLAKE2b-256 |
a82885e5d074b7b3f63d773bf338fdbef526747978d90d9ca3d441cf75d01f15
|
Provenance
The following attestation bundles were made for worldcatclient-0.8.5-py3-none-any.whl:
Publisher:
python-publish.yml on bluebinary/worldcat-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
worldcatclient-0.8.5-py3-none-any.whl -
Subject digest:
696852baf5f587f2d5c9306de28dc5809defeca3f469bd92a3c24981363cf7d0 - Sigstore transparency entry: 1775957845
- Sigstore integration time:
-
Permalink:
bluebinary/worldcat-client@4a55d4a1eda39b860cf0372c8771859beec6b4dc -
Branch / Tag:
refs/tags/v0.8.5 - Owner: https://github.com/bluebinary
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4a55d4a1eda39b860cf0372c8771859beec6b4dc -
Trigger Event:
release
-
Statement type: