Skip to main content

API client for the Arkindex project

Project description

API documentation available at https://arkindex.gitlab.io/api-client/

arkindex-client provides an API client to interact with Arkindex servers.

Setup

Install the client using pip:

pip install arkindex-client

Usage

To create a client and login using an email/password combo, use the ArkindexClient.login helper method:

from arkindex import ArkindexClient
cli = ArkindexClient()
cli.login('EMAIL', 'PASSWORD')

This helper method will save the authentication token in your API client, so that it is reused in later API requests.

If you already have an API token, you can create your client like so:

from arkindex import ArkindexClient
cli = ArkindexClient('YOUR_TOKEN')

To perform a simple API request, you can use the request() method. The method takes an operation ID as a name and the operation’s parameters as keyword arguments:

Making requests

corpus = cli.request('RetrieveCorpus', id='...')

The result will be a Python dict containing the result of the API request. If the request returns an error, an apistar.exceptions.ErrorResponse will be raised.

Dealing with pagination

The Arkindex client adds another helper method for paginated endpoints that deals with pagination for you: ArkindexClient.paginate. This method returns a ResponsePaginator instance, which is a classic Python iterator that does not perform any actual requests until absolutely needed: that is, until the next page must be loaded.

for page in cli.paginate('ListCorpusPages', id=corpus['id']):
    print(page['display_name'])

Warning: Using list on a ResponsePaginator may load dozens of pages at once and cause a big load on the server. You can use len to get the total item count before spamming a server.

Using another server

By default, the API client is set to point to the main Arkindex server at https://arkindex.teklia.com. If you need or want to use this API client on another server, you can use the base_url keyword argument when setting up your API client:

cli = ArkindexClient(base_url='https://somewhere')

Examples

Create transcriptions in bulk

payload = {
    "parent": "ELEMENT_ID",
    "recognizer": "ML_TOOL_SLUG",
    "transcriptions": [
        {
            # A polygon, as a list of at least 3 [x, y] points
            "polygon": [
                [100, 100],
                [100, 300],
                [200, 300],
                [200, 100],
            ],
            # The confidence score
            "score": 0.8,
            # Recognized text
            "text": "Blah",
            # Transcription type: page, paragraph, line, word, character
            "type": "word",
        },
        # ...
    ]
}
cli.request('CreateTranscriptions', body=payload)

Download full logs for each Ponos task in a workflow

workflow = cli.request('RetrieveWorkflow', id='...')
for task in workflow['tasks']:
    with open(task['id'] + '.txt', 'w') as f:
        f.write(cli.request('RetrieveTaskLog', id=task['id']))

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

arkindex-client-0.2.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

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

arkindex_client-0.2.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file arkindex-client-0.2.0.tar.gz.

File metadata

  • Download URL: arkindex-client-0.2.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for arkindex-client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 73e91a7e6e8a28907cffb6100325bc032ee4930430db4f1c446c04a2d42338f7
MD5 6e808ae9677d8c39e3b5721054a0d91d
BLAKE2b-256 41fc5af955109c56da14434d4dc72f0a4a89885da3f636937a2c46fe9d102a9f

See more details on using hashes here.

File details

Details for the file arkindex_client-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: arkindex_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for arkindex_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 966c7cf3eec04ce2696c8bf52d48d4a606a66f2b174a1bdf621fa370d52bfac7
MD5 d3518db877249eca27f33a575ef03738
BLAKE2b-256 36c7e2921e923c33836639454f961236b4984c3e798da2868f437ab24f99cdd8

See more details on using hashes here.

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