Skip to main content

Python client library for accessing Annif REST API

Project description


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.


The easiest way to install is via pip:

pip3 install annif-client


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 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
Demonstrating usage of AnnifClient

* Creating an AnnifClient object
Now we have an AnnifClient object: AnnifClient(api_base='')

* Finding the available projects
Project id: yso-fi           lang: fi  name: YSO ensemble Finnish
Project id: yso-sv           lang: sv  name: YSO ensemble Swedish
Project id: yso-en           lang: en  name: YSO ensemble English
Project id: tfidf-fi         lang: fi  name: TF-IDF Finnish
Project id: tfidf-sv         lang: sv  name: TF-IDF Swedish
Project id: tfidf-en         lang: en  name: TF-IDF English
Project id: fasttext-fi      lang: fi  name: fastText Finnish
Project id: fasttext-sv      lang: sv  name: fastText Swedish
Project id: fasttext-en      lang: en  name: fastText English
Project id: maui-fi          lang: fi  name: Maui Finnish
Project id: maui-sv          lang: sv  name: Maui Swedish
Project id: maui-en          lang: en  name: Maui English
Project id: annif-api-fi     lang: fi  name: Annif prototype API Finnish
Project id: annif-api-sv     lang: sv  name: Annif prototype API Swedish
Project id: annif-api-en     lang: en  name: Annif prototype API English
Project id: ykl-fasttext-fi  lang: fi  name: YKL fastText Finnish

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

* Analyzing a short text from a string
<>	0.2595	red fox
<>	0.2039	dog
<>	0.1946	laziness
<>	0.1285	brown
<>	0.1220	triple jump
<>	0.1194	long jump
<>	0.1109	canines
<>	0.1094	blue fox
<>	0.1068	high jump
<>	0.0911	animal training

* Analyzing a longer text from a file, with a limit on number of results
<>	0.3651	licences (permits)
<>	0.1656	copyright
<>	0.1566	national libraries
<>	0.1461	Apache
<>	0.1220	copies


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.

Files for annif-client, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size annif_client-0.3.0-py3-none-any.whl (4.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size annif-client-0.3.0.tar.gz (3.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page