Skip to main content

Python client library for accessing Annif REST API

Project description

Annif-client

This is a minimal Python 3.x client library for accessing the Annif REST API which can be used for automated subject indexing and classification of text documents.

Installation

The easiest way to install is via pip:

pip3 install annif-client

Dependencies

The library depends on the requests module which is used for HTTP/REST access. If you install this via pip, the dependencies will be handled automatically.

How to use

The client library comes with examples demonstrating its usage. You can invoke the example by running the annif_client.py script.

In your own code, you can use the AnnifClient class like this:

from annif_client import AnnifClient

# then you can create your own client
annif = AnnifClient()

Example invocation

Here is the output from a typical example session:

$ python3 annif_client.py
Demonstrating usage of AnnifClient

* Creating an AnnifClient object
* The client uses Annif API at https://api.annif.org/v1/
* The version of Annif serving the API is 1.4.0

* Detecting the language of text: 'The quick brown fox jumped over the lazy dog' (candidates: en, fi, sv)
Language: en    score: 1.0
Language: sv    score: 0.25
Language: fi    score: 0.0
Language: None  score: 0.0

* Finding the available projects
Project id: yso-fi           lang: fi  name: YSO NN ensemble Finnish
Project id: yso-sv           lang: sv  name: YSO NN ensemble Swedish
Project id: yso-en           lang: en  name: YSO NN ensemble English
Project id: yso-mllm-fi      lang: fi  name: YSO MLLM Finnish
Project id: yso-mllm-en      lang: en  name: YSO MLLM English
Project id: yso-mllm-sv      lang: sv  name: YSO MLLM Swedish
Project id: yso-bonsai-fi    lang: fi  name: YSO Omikuji Bonsai Finnish
Project id: yso-bonsai-sv    lang: sv  name: YSO Omikuji Bonsai Swedish
Project id: yso-bonsai-en    lang: en  name: YSO Omikuji Bonsai English
Project id: yso-fasttext-fi  lang: fi  name: YSO fastText Finnish
Project id: yso-fasttext-sv  lang: sv  name: YSO fastText Swedish
Project id: yso-fasttext-en  lang: en  name: YSO fastText English

* Looking up information about a specific project
Project id: yso-en           lang: en  name: YSO NN ensemble English

* Analyzing a short text from a string
<http://www.yso.fi/onto/yso/p5319>	0.2852	dog
<http://www.yso.fi/onto/yso/p8122>	0.1401	laziness
<http://www.yso.fi/onto/yso/p2228>	0.1052	red fox
<http://www.yso.fi/onto/yso/p2352>	0.0914	singers
<http://www.yso.fi/onto/yso/p675>	0.0679	pets
<http://www.yso.fi/onto/yso/p27825>	0.0651	jumping
<http://www.yso.fi/onto/yso/p25726>	0.0631	brown
<http://www.yso.fi/onto/yso/p2023>	0.0584	animals
<http://www.yso.fi/onto/yso/p4484>	0.0453	jazz
<http://www.yso.fi/onto/yso/p22993>	0.0357	clicker training

* Analyzing a longer text from a file, with a limit on number of results
<http://www.yso.fi/onto/yso/p2346>	0.6324	copyright
<http://www.yso.fi/onto/yso/p16495>	0.4211	licences (permits)
<http://www.yso.fi/onto/yso/p26592>	0.1882	computer programmes
<http://www.yso.fi/onto/yso/p3069>	0.1434	patents
<http://www.yso.fi/onto/yso/p3068>	0.1044	intellectual property law

* Analyzing a batch of text documents
doc-0
<http://www.yso.fi/onto/yso/p5319>	0.2852	dog
<http://www.yso.fi/onto/yso/p8122>	0.1401	laziness
<http://www.yso.fi/onto/yso/p2228>	0.1052	red fox
<http://www.yso.fi/onto/yso/p2352>	0.0914	singers
<http://www.yso.fi/onto/yso/p675>	0.0679	pets
<http://www.yso.fi/onto/yso/p27825>	0.0651	jumping
<http://www.yso.fi/onto/yso/p25726>	0.0631	brown
<http://www.yso.fi/onto/yso/p2023>	0.0584	animals
<http://www.yso.fi/onto/yso/p4484>	0.0453	jazz
<http://www.yso.fi/onto/yso/p22993>	0.0357	clicker training
doc-1
<http://www.yso.fi/onto/yso/p1780>	0.7189	history
<http://www.yso.fi/onto/yso/p2787>	0.7167	libraries
<http://www.yso.fi/onto/yso/p11657>	0.6425	national libraries
<http://www.yso.fi/onto/yso/p94426>	0.3903	Finland
<http://www.yso.fi/onto/yso/p12676>	0.3430	collections
<http://www.yso.fi/onto/yso/p8025>	0.2621	architecture
<http://www.yso.fi/onto/yso/p4860>	0.2586	library buildings
<http://www.yso.fi/onto/yso/p19136>	0.2577	scientific libraries
<http://www.yso.fi/onto/yso/p1778>	0.2208	histories (literary works)
<http://www.yso.fi/onto/yso/p10184>	0.2120	university libraries
doc-2
<http://www.yso.fi/onto/yso/p4934>	0.5751	museums
<http://www.yso.fi/onto/yso/p2787>	0.5510	libraries
<http://www.yso.fi/onto/yso/p2336>	0.4488	archives (memory organisations)
<http://www.yso.fi/onto/yso/p26984>	0.4123	subject indexing
<http://www.yso.fi/onto/yso/p11477>	0.2768	automation
<http://www.yso.fi/onto/yso/p13380>	0.2394	subject cataloging
<http://www.yso.fi/onto/yso/p39257>	0.1884	indexing (information technology)
<http://www.yso.fi/onto/yso/p1140>	0.0799	data storage
<http://www.yso.fi/onto/yso/p5521>	0.0771	information management
<http://www.yso.fi/onto/yso/p21192>	0.0749	long-term preservation

License

The code is published under the Apache 2.0 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

annif_client-0.5.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

annif_client-0.5.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file annif_client-0.5.0.tar.gz.

File metadata

  • Download URL: annif_client-0.5.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for annif_client-0.5.0.tar.gz
Algorithm Hash digest
SHA256 92d553e997da5d5ab2aaca947af736837a93f3f5386ed76ae0b2ade7c4e8f245
MD5 1ba5495515bb4a58a765ae2dcc8795f8
BLAKE2b-256 c44e9f9d8b58977fc0ffd6190d1a9b03e76f8b5f42bde3fd8c1517b553abe351

See more details on using hashes here.

Provenance

The following attestation bundles were made for annif_client-0.5.0.tar.gz:

Publisher: python-package.yml on NatLibFi/Annif-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file annif_client-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: annif_client-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for annif_client-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39f3a9a0900b7c3dc2f94da41e28583905830d2949cf8be4241849bb5b1565ca
MD5 ab439010a2f0775efeb739afaf9050d7
BLAKE2b-256 f8aa6cc42f62fb573846ea4358cafb2c15c20d2f687080dc5360792b6bda43b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for annif_client-0.5.0-py3-none-any.whl:

Publisher: python-package.yml on NatLibFi/Annif-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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