Skip to main content

Official SDK for the AnnoLab Platform

Project description

Version

This is the official python SDK for AnnoLab, the ML platform for NLP projects.

AnnoLab Website

Getting Started

Assuming that you have Python and virtualenv installed, set up your environment and install the required dependencies like this or you can install the library using pip:

$ virtualenv venv
$ . venv/bin/activate
$ python -m pip install annolab

Using the AnnoLab SDK

To get started, ensure you have an annolab account at https://app.annolab.ai/signup and have created an API Key. Instructions for creating an API Key may be found at https://docs.annolab.ai/.

Configure the sdk with your api key using one of the following two methods.

  1. Create an instance of the SDK passing your api_key.

>>> from annolab import Annolab
>>> lab = AnnoLab(api_key='YOUR_API_KEY')
  1. Or set a global api key. All subsequent uses of the sdk will use this global key for authentication.

>>> import annolab
>>> from annolab import Annolab
>>>
>>> annolab.api_key = 'YOUR_API_KEY'
>>> lab = AnnoLab()

Usage Examples

Creating a project.

lab.create_project('My New Project')
# OR
lab.create_project(name='My New Project', owner_name='AnnoLab')

Getting an existing project.

lab.find_project('My New Project')
# OR
lab.find_project(name='My New Project', owner_name='AnnoLab')

Creating a new text source. Will be added to the “Uploads” directory by default.

project = lab.find_project('My New Project')
project.create_text_source(name='New Source', text='Some text or tokens for annotation.')
# Specifying a directory
project.create_text_source(
  name='New Source',
  text='Some text or tokens for annotation.',
  directory='Uploads'
)

Creating a new pdf source from a file. Will be added to the “Uploads” directory by default.

project = annolab.find_project('My New Project')
project.create_pdf_source(file='/path/to/file')
project.create_pdf_source(file='/path/to/file', name='custom_name.pdf', directory='Uploads')

# You may also pass a filelike object or bytes. "name" is required when doing so.
project.create_pdf_source(file=open('myfile.pdf', 'r+b'), name='myfile.pdf')

Creating a new pdf source from a web source.

project = annolab.find_project('My New Project')
project.create_pdf_source_from_web(url='https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf', name='mypdf.pdf')

Adding annotations.

  project.create_annotations(
    source_name='New Source',
    annotations=[
        { 'type': 'one', 'value': 'value one', 'offsets': [0, 10]},
        { 'type': 'two', 'value': 'two', 'offsets': [10, 20] }
    ],
)

Adding annotations with relations.

  project.create_annotations(
    source_name='New Source',
    annotations=[
        { 'clientId': 1, 'type': 'one', 'value': 'value one', 'offsets': [0, 10]},
        { 'clientId': 2, 'type': 'two', 'value': 'two', 'offsets': [10, 20] }
    ],
    relations=[
      { 'annotations': [1, 2] }
    ]
)

Exporting a project.

project.export(filepath='/path/to/outfile.zip')

# With options
project.export(
  filepath='/path/to/outfile.zip',
  source_ids=[1,2,3],
  layers=['GoldSet'],
  include_annotation_types=True,
  include_sources=True
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

annolab-0.3.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file annolab-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: annolab-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for annolab-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 30e15a4a986412a4ef5cea662ef29138f26042dfea084e9cf15cb95a7128d2d6
MD5 b497b782e212a2836dacd23b25b0df96
BLAKE2b-256 f17e897ac9ab43f70b99be42b6ef05931e4f77bf700112e90d8d39eaac142482

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