Skip to main content

Python client for Thoth's APIs

Project description

Python client for Thoth's GraphQL and REST APIs. Currently supports Thoth version 0.6.0.

Release PyPi version

Usage

Install

Install is either via pip or cloning the repository.

From pip:

python3 -m pip install thothlibrary==0.10.3

Or from the repo:

git clone git@github.com:dqprogramming/thoth-client.git
cd thoth-client
pip3 install -r ./requirements.txt

GraphQL Usage

from thothlibrary import ThothClient

thoth = ThothClient()
print(thoth.works())

CLI GraphQL Usage

python3 -m thothlibrary.cli contribution --contribution_id=29e4f46b-851a-4d7b-bb41-e6f305fc2b11
python3 -m thothlibrary.cli contributions --limit=10
python3 -m thothlibrary.cli contribution_count
python3 -m thothlibrary.cli contributor --contributor_id=e8def8cf-0dfe-4da9-b7fa-f77e7aec7524
python3 -m thothlibrary.cli contributors --limit=10
python3 -m thothlibrary.cli contributor_count --search="Vincent"
python3 -m thothlibrary.cli institution --institution_id=194614ac-d189-4a74-8bf4-74c0c9de4a81
python3 -m thothlibrary.cli institutions --limit=10
python3 -m thothlibrary.cli funder_count
python3 -m thothlibrary.cli funding --funding_id=5323d3e7-3ae9-4778-8464-9400fbbb959e
python3 -m thothlibrary.cli fundings --limit=10
python3 -m thothlibrary.cli imprint --imprint_id=78b0a283-9be3-4fed-a811-a7d4b9df7b25
python3 -m thothlibrary.cli imprints --limit=25 --offset=0 --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b" "9c41b13c-cecc-4f6a-a151-be4682915ef5"]'
python3 -m thothlibrary.cli imprint_count --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b" "9c41b13c-cecc-4f6a-a151-be4682915ef5"]'
python3 -m thothlibrary.cli issue --issue_id=6bd31b4c-35a9-4177-8074-dab4896a4a3d
python3 -m thothlibrary.cli issues --limit=10
python3 -m thothlibrary.cli issue_count
python3 -m thothlibrary.cli language --language_id=c19e68dd-c5a3-48f1-bd56-089ee732604c
python3 -m thothlibrary.cli languages --limit=10 --language_code=CHI
python3 -m thothlibrary.cli language_count --language_code=CHI
python3 -m thothlibrary.cli price --price_id=818567dd-7d3a-4963-8704-3381b5432877
python3 -m thothlibrary.cli prices --limit=10 --currency_code=GBP
python3 -m thothlibrary.cli price_count --currency_code=GBP
python3 -m thothlibrary.cli publication --publication_id=27b7bdab-e9e5-4220-811e-1f370861f5e1
python3 -m thothlibrary.cli publications --limit=10 --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b"]'
python3 -m thothlibrary.cli publication_count --publication_type="HARDBACK"
python3 -m thothlibrary.cli publisher --publisher_id=85fd969a-a16c-480b-b641-cb9adf979c3b
python3 -m thothlibrary.cli publishers --limit=10 --order='{field: PUBLISHER_ID, direction: ASC}' --offset=0 --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b" "9c41b13c-cecc-4f6a-a151-be4682915ef5"]'
python3 -m thothlibrary.cli publisher_count --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b" "9c41b13c-cecc-4f6a-a151-be4682915ef5"]'
python3 -m thothlibrary.cli series --series_id=d4b47a76-abff-4047-a3c7-d44d85ccf009
python3 -m thothlibrary.cli serieses --limit=3 --search="Classics"
python3 -m thothlibrary.cli series_count --series_type=BOOK_SERIES
python3 -m thothlibrary.cli subject --subject_id=1291208f-fc43-47a4-a8e6-e132477ad57b
python3 -m thothlibrary.cli subjects --limit=10 --subject_type=BIC
python3 -m thothlibrary.cli subject_count --subject_type=THEMA
python3 -m thothlibrary.cli supported_versions
python3 -m thothlibrary.cli update_cover --doi="https://doi.org/10.11647/OBP.0278" --url="https://cdn.openbookpublishers.com/covers/10.11647/obp.0278.jpg"
python3 -m thothlibrary.cli work --doi="https://doi.org/10.11647/OBP.0222"
python3 -m thothlibrary.cli work --work_id="e0f748b2-984f-45cc-8b9e-13989c31dda4"
python3 -m thothlibrary.cli works --limit=10 --order='{field: PUBLICATION_DATE, direction: DESC}' --work_status=ACTIVE --work_type=MONOGRAPH --offset=1 --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b"]'
python3 -m thothlibrary.cli work_count --publishers='["85fd969a-a16c-480b-b641-cb9adf979c3b"]'

REST Usage

from thothlibrary import ThothRESTClient

client = ThothRESTClient()
print(client.formats())

CLI REST Usage

python3 -m thothrest.cli
python3 -m thothrest.cli formats
python3 -m thothrest.cli formats --return-json
python3 -m thothrest.cli work onix_3.0::project_muse e0f748b2-984f-45cc-8b9e-13989c31dda4

Thoth Django

The thothdjango folder includes models, an import routine, subject-code support, and admin procedures to use Thoth in a django app. The import provides unidirectional synchronization from remote Thoth imports to a local database for use in a Django app.

Test Suite

Tests for GraphQL queries are versioned in the thoth-[ver] folder of thothlibrary.

Tests confirm that current code produces good, known object outputs from stored GraphQL input.

Versioning

The Thoth API is not yet considered stable and functionality changes between versions. The recommended way to add a new version compatibility is:

  1. Read the latest Thoth changelog to understand the changes.
  2. Copy the latest thoth-[ver] folder to the correctly named new version.
  3. Find and replace the strings specified in genfixtures.sh and genjson.sh. Update the version string in tests and endpoints.
  4. Run genjson.sh only from inside the tests directory of the new version. This will fetch the latest server JSON responses and store it inside the fixtures directory for these tests. If there are any errors, then the command line CLI has encountered a breaking change that must first be fixed.
  5. Run the test suite for the latest version and examine breakages. It is possible that breakages are not actually full breakdown, but merely a change in the serialized object. Nonetheless, fix these by subclassing the previous versions of the API and overriding broken methods. In the cases of total breakage, a non-subclassed rewrite may be more appropriate. (May also apply at major version breaks.)
  6. When the test suite passes, or a new object format has been decided and tests rewritten, run genfixtures.sh to freeze the current test suite.
  7. Include the new version directory in the list of packages in setup.py
  8. Update THOTH_VERSION in thothlibrary/client.py

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

thothlibrary-0.10.3.tar.gz (45.6 kB view details)

Uploaded Source

Built Distributions

thothlibrary-0.10.3-py3.9.egg (105.1 kB view details)

Uploaded Source

thothlibrary-0.10.3-py3-none-any.whl (51.2 kB view details)

Uploaded Python 3

File details

Details for the file thothlibrary-0.10.3.tar.gz.

File metadata

  • Download URL: thothlibrary-0.10.3.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for thothlibrary-0.10.3.tar.gz
Algorithm Hash digest
SHA256 ede7022595c981d025128f26382faea1d9f38d5faec5c95d59436f95bf25fe2d
MD5 e9060a5e0fdafb1326631ad203487ad8
BLAKE2b-256 9590ce921a674397d05ec28625242537ee7bf6f906c3330ecf4632403106a37a

See more details on using hashes here.

Provenance

File details

Details for the file thothlibrary-0.10.3-py3.9.egg.

File metadata

  • Download URL: thothlibrary-0.10.3-py3.9.egg
  • Upload date:
  • Size: 105.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for thothlibrary-0.10.3-py3.9.egg
Algorithm Hash digest
SHA256 6b49089db31e0667c8d8daf162d4e5174206cdaf3885fe112a537590ded9b8e8
MD5 d40b84229f79c72724ba473bc84782dd
BLAKE2b-256 ef20c77fa4dc3f8d6ae59019112da14385ce1a1e702de7bc88cd61943d835242

See more details on using hashes here.

Provenance

File details

Details for the file thothlibrary-0.10.3-py3-none-any.whl.

File metadata

  • Download URL: thothlibrary-0.10.3-py3-none-any.whl
  • Upload date:
  • Size: 51.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for thothlibrary-0.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 22f9c8c9abf6eaaaa2925b5c8847b1d280f05600ca532570ea3164d788ab8ec5
MD5 7dae3aabc74a65da08a20dfa549812b4
BLAKE2b-256 fc9591077bf0190ed1637dc53f543bfe2a9ca22dd56e8a17115b8b97d455d5d8

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page