Skip to main content

Public python module for tagias.com external API

Project description

tagias-python

Public python module for tagias.com external API

Installation

pip install tagias

or

python -m pip install tagias

Documentation

You can find the detailed documentation for our external REST API at the API Reference page

Source code

You can find the source code on its GitHub page https://github.com/tagias/tagias-python.git

Usage

This helper module was designed to simplify the way you are using the tagias.com external API

You can use the TagiasHelper class to get responses as JSON objects.

# import the tagias api helper classes
from tagias.tagias import TagiasHelper, TagiasError, TagiasTypes, TagiasStatuses

# Replace the test API key with your own private API key
apiKey = 'test'

# Testing the TAGIAS external API methods using TagiasHelper class
try:
    print('Test Start')

    # create tagias helper object
    helper = TagiasHelper(apiKey)

    # create a new package
    newPackage = helper.create_package('Test package', TagiasTypes.Keypoints,
      'Put one point only in the center of the image', None, None,
      'https://p.tagias.com/samples/', ['dog.8001.jpg', 'dog.8002.jpg', 'dog.8003.jpg'])
    
    print('Package {} was created with {} image(s)'.format(newPackage['id'], newPackage['pictures_num']))

    try:
        # modify the package's status
        helper.set_package_status(newPackage['id'], TagiasStatuses.STOPPED)
    except TagiasError as e:
        # handle a TagiasError exception
        print('{} package\'s status was NOT modified: {}'.format(newPackage['id'], e.message))

    # get the package's properties
    package = helper.get_package(newPackage['id'])
    print('New package properties:')
    for prop in package:
        print (' * {}: {}'.format(prop, package[prop]))

    # get the list of all your packages
    packages = helper.get_packages()
    print('Packages:')
    for package in packages:
        print(' * {} {} {} {}'.format(package['id'], package['name'], package['status'], package['created']))
        if package['status']==TagiasStatuses.FINISHED:
            # get the package's result if it's already finished
            result = helper.get_result(package['id'])
            print(result)

            try:
                # request the package's result to be send to the callback endpoint
                helper.request_result(package['id'])
            except TagiasError as e:
                # handle a TagiasError exception
                print('{} package\'s result was NOT requested: {}'.format(package['id'], e.message))

    # get current balance and financial operations
    balance = helper.get_balance()
    print('Current balance: {} USD'.format(balance['balance']))
    print('Operations:')
    for op in balance['operations']:
        print(' * {}: {} USD, {}'.format(op['date'], op['amount'], op['note']))

    print('Test End')
except TagiasError as e:
    # handle a TagiasError exception
    print('TagiasError: {} ({})'.format(e.message, e.code))

Or you can use the TagiasHelper2 class to get responses as class instances with all needed attributes.

The TagiasPackage, TagiasNewPackage, TagiasFullPackage, TagiasResult, TagiasBalance, TagiasOperation classes are defined to hold the response information converted to objects with attributes.

The TagiasResult class contains the pictures list of TagiasPictureResult class instances.

And the TagiasPictureResult class contains either the datalist attribute (a list of TagiasBoundingBox, TagiasLine, TagiasPoligon, TagiasKeypoint classes instances) or the data attribute (an instance of TagiasClassificationSingle or TagiasClassificationMultiple class).

There is also the result attribute of the TagiasPictureResult class that contains JSON object with annotation results.

# import the tagias api helper classes using TagiasHelper2 class
from tagias.tagias import TagiasHelper2, TagiasError, TagiasTypes, TagiasStatuses

# Replace the test API key with your own private API key
apiKey = 'test'

# Testing the TAGIAS external API methods
try:
    print('Test2 Start')

    # create tagias helper object
    helper = TagiasHelper2(apiKey)

    # create a new package
    newPackage = helper.create_package('Test package', TagiasTypes.Keypoints,
        'Put one point only in the center of the image', None, None,
        'https://p.tagias.com/samples/', ['dog.8001.jpg', 'dog.8002.jpg', 'dog.8003.jpg'])

    print('Package {} was created with {} image(s)'.format(newPackage.id, newPackage.pictures_num))

    try:
        # modify the package's status
        helper.set_package_status(newPackage.id, TagiasStatuses.STOPPED)
    except TagiasError as e:
        # handle a TagiasError exception
        print('{} package\'s status was NOT modified: {}'.format(newPackage.id, e.message))

    # get the package's properties
    package = helper.get_package(newPackage.id)
    print('New package properties:')
    for prop in dir(package):
        if not prop.startswith('_'):
            print(' * {}: {}'.format(prop, getattr(package, prop)))

    # get the list of all your packages
    packages = helper.get_packages()
    print('Packages:')
    for package in packages:
        print(' * {} {} {} {}'.format(package.id, package.name, package.status, package.created))
        if package.status == TagiasStatuses.FINISHED:
            # get the package's result if it's already finished
            result = helper.get_result(package.id)
            print(result)

            try:
                # request the package's result to be send to the callback endpoint
                helper.request_result(package.id)
            except TagiasError as e:
                # handle a TagiasError exception
                print('{} package\'s result was NOT requested: {}'.format(package.id, e.message))

    # get current balance and financial operations
    balance = helper.get_balance()
    print('Current balance: {} USD'.format(balance.balance))
    print('Operations:')
    for op in balance.operations:
        print(' * {}: {} USD, {}'.format(op.date, op.amount, op.note))

    print('Test2 End')
except TagiasError as e:
    # handle a TagiasError exception
    print('TagiasError: {} ({})'.format(e.message, e.code))

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

tagias-1.2.0.tar.gz (7.8 kB view details)

Uploaded Source

File details

Details for the file tagias-1.2.0.tar.gz.

File metadata

  • Download URL: tagias-1.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5

File hashes

Hashes for tagias-1.2.0.tar.gz
Algorithm Hash digest
SHA256 a003a70e3aa173beb0fc5b587a9dc67cca9dd6935cc4655c15647e3a873cdf6e
MD5 bce780f6d3a3cf62aecd698c98dbb76d
BLAKE2b-256 d4db5c561125de8c38939b6ea593c46ef1aa1b8c090bf0e8c7752ed78f4498f5

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