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 0.61.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.4.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

annif_client-0.4.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file annif-client-0.4.0.tar.gz.

File metadata

  • Download URL: annif-client-0.4.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for annif-client-0.4.0.tar.gz
Algorithm Hash digest
SHA256 36fce73bc4663ebf9b727dae8b747a47772370f2c8359d1e3ae66dc96e9bfd04
MD5 f348e9150f4222544e6bdcc91badf030
BLAKE2b-256 64962b53940dfeeca28224df6fae9ba7b9d33d3b0fe26bcae6d68ca56e658a7b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: annif_client-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for annif_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1182624db2da0b02fede7a1766e44c480af7a2f9d9f37dc1aa284528cae3077
MD5 9f6df66023603f18c00cc47669a7fb00
BLAKE2b-256 1f16c81bd476a56a211c0b6643a13c7dfc6f4f9430a96943f2231054778f984d

See more details on using hashes here.

Supported by

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