Package: tagias
tagias-pythonPublic python module for tagias.com external APIInstallationpip install tagiasorpython -m pip install tagiasDocumentationYou can find the detailed documentation for our external REST API at theAPI ReferencepageSource codeYou can find the source code on its GitHub pagehttps://github.com/tagias/tagias-python.gitUsageThis helper module was designed to simplify the way you are using the tagias.com external APIYou can use theTagiasHelperclass to get responses as JSON objects.# import the tagias api helper classesfromtagias.tagiasimportTagiasHelper,TagiasError,TagiasTypes,TagiasStatuses# Replace the test API key with your own private API keyapiKey='test'# Testing the TAGIAS external API methods using TagiasHelper classtry:print('Test Start')# create tagias helper objecthelper=TagiasHelper(apiKey)# create a new packagenewPackage=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 statushelper.set_package_status(newPackage['id'],TagiasStatuses.STOPPED)exceptTagiasErrorase:# handle a TagiasError exceptionprint('{}package\'s status was NOT modified:{}'.format(newPackage['id'],e.message))# get the package's propertiespackage=helper.get_package(newPackage['id'])print('New package properties:')forpropinpackage:print(' *{}:{}'.format(prop,package[prop]))# get the list of all your packagespackages=helper.get_packages()print('Packages:')forpackageinpackages:print(' *{}{}{}{}'.format(package['id'],package['name'],package['status'],package['created']))ifpackage['status']==TagiasStatuses.FINISHED:# get the package's result if it's already finishedresult=helper.get_result(package['id'])print(result)try:# request the package's result to be send to the callback endpointhelper.request_result(package['id'])exceptTagiasErrorase:# handle a TagiasError exceptionprint('{}package\'s result was NOT requested:{}'.format(package['id'],e.message))# get current balance and financial operationsbalance=helper.get_balance()print('Current balance:{}USD'.format(balance['balance']))print('Operations:')foropinbalance['operations']:print(' *{}:{}USD,{}'.format(op['date'],op['amount'],op['note']))print('Test End')exceptTagiasErrorase:# handle a TagiasError exceptionprint('TagiasError:{}({})'.format(e.message,e.code))Or you can use theTagiasHelper2class to get responses as class instances with all needed attributes.TheTagiasPackage, TagiasNewPackage, TagiasFullPackage, TagiasResult, TagiasBalance, TagiasOperationclasses are defined to hold the response information converted to objects with attributes.TheTagiasResultclass contains thepictureslist ofTagiasPictureResultclass instances.And theTagiasPictureResultclass contains either thedatalistattribute (a list ofTagiasBoundingBox,TagiasLine,TagiasPoligon,TagiasKeypointclasses instances) or thedataattribute (an instance ofTagiasClassificationSingleorTagiasClassificationMultipleclass).There is also theresultattribute of theTagiasPictureResultclass that contains JSON object with annotation results.# import the tagias api helper classes using TagiasHelper2 classfromtagias.tagiasimportTagiasHelper2,TagiasError,TagiasTypes,TagiasStatuses# Replace the test API key with your own private API keyapiKey='test'# Testing the TAGIAS external API methodstry:print('Test2 Start')# create tagias helper objecthelper=TagiasHelper2(apiKey)# create a new packagenewPackage=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 statushelper.set_package_status(newPackage.id,TagiasStatuses.STOPPED)exceptTagiasErrorase:# handle a TagiasError exceptionprint('{}package\'s status was NOT modified:{}'.format(newPackage.id,e.message))# get the package's propertiespackage=helper.get_package(newPackage.id)print('New package properties:')forpropindir(package):ifnotprop.startswith('_'):print(' *{}:{}'.format(prop,getattr(package,prop)))# get the list of all your packagespackages=helper.get_packages()print('Packages:')forpackageinpackages:print(' *{}{}{}{}'.format(package.id,package.name,package.status,package.created))ifpackage.status==TagiasStatuses.FINISHED:# get the package's result if it's already finishedresult=helper.get_result(package.id)print(result)try:# request the package's result to be send to the callback endpointhelper.request_result(package.id)exceptTagiasErrorase:# handle a TagiasError exceptionprint('{}package\'s result was NOT requested:{}'.format(package.id,e.message))# get current balance and financial operationsbalance=helper.get_balance()print('Current balance:{}USD'.format(balance.balance))print('Operations:')foropinbalance.operations:print(' *{}:{}USD,{}'.format(op.date,op.amount,op.note))print('Test2 End')exceptTagiasErrorase:# handle a TagiasError exceptionprint('TagiasError:{}({})'.format(e.message,e.code))