v2.0

Module contents

class las.BaseClient(credentials: Optional[las.credentials.Credentials] = None)

Bases: object

A low level client to invoke api methods from Lucidtech AI Services.

create_batch(description: str)

Creates a batch handle, calls the POST /batches endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.create_batch(description='Data from clients obtained during fall 2019')
  • Parameters

    description (str) – A short description of the batch you intend to create

  • Returns

    batch handle id and pre-signed upload url

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException,

LimitExceededException, requests.exception.RequestException

Creates a document handle, calls the POST /documents endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.create_document(b'<bytes data>', 'image/jpeg', '<consent id>')
  • Parameters

  • content (bytes) – The contents to POST

  • content_type (str) – A mime type for the document handle

  • consent_id (str) – An identifier to mark the owner of the document handle

  • batch_id (str) – The batch to put the document in

  • feedback (Sequence[Dict[str, str]]) – A list of feedback items {label: value} representing the ground truth values for the document

  • Returns

    Document handle id

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

create_prediction(document_id: str, model_name: str, max_pages: Optional[int] = None, auto_rotate: Optional[bool] = None, extras: Dict[str, Any] = None)

Create a prediction on a document using specified model, calls the POST /predictions endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.create_prediction(document_id='<document id>', model_name='invoice')
  • Parameters

  • document_id (str) – The document id to run inference and create a prediction on

  • model_name (str) – The name of the model to use for inference

  • max_pages (int) – Maximum number of pages to run predictions on

  • auto_rotate (bool) – Whether or not to let the API try different rotations on the document when running predictions

  • extras (Dict[str, Any**]) – Extra information to add to json body

  • Returns

    Prediction on document

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

Delete documents with this consent_id, calls the DELETE /consents/{consentId} endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.delete_consent('<consent id>')
  • Parameters

    consent_id (str) – Delete documents with this consent_id

  • Returns

    Delete consent id response from REST API

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

get_document(document_id: str)

Get document from the REST API, calls the GET /documents/{documentId} endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.get_document(document_id='<document id>')
  • Parameters

    document_id (str) – The document id to run inference and create a prediction on

  • Returns

    Document response from REST API

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

get_user(user_id: str)

Get information about user, calls the GET /users/{user_id} endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.get_user('me')
  • Parameters

    user_id (str) – The user_id to get consent hash for

  • Returns

    batch handle id and pre-signed upload url

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

List documents that you have created, calls the GET /documents endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.list_documents()
  • Parameters

  • batch_id (str) – The batch id that contains the documents of interest

  • consent_id (str) – An identifier to mark the owner of the document handle

  • Returns

    Documents from REST API contained in batch

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

update_document(document_id: str, feedback: Sequence[Dict[str, str]])

Post feedback to the REST API, calls the POST /documents/{documentId} endpoint. Posting feedback means posting the ground truth data for the particular document. This enables the API to learn from past mistakes.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> feedback = [{'label': 'total_amount', 'value': '156.00'}, {'label': 'invoice_date', 'value': '2018-10-23'}]
>>> client.update_document(document_id='<document id>', feedback=feedback)
  • Parameters

  • document_id (str) – The document id to run inference and create a prediction on

  • feedback (Sequence[Dict[str, str]]) – A list of feedback items {label: value} representing the ground truth values for the document

  • Returns

    Feedback response from REST API

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

Modifies consent hash for user, calls the PATCH /users/{user_id} endpoint.

>>> from las.client import BaseClient
>>> client = BaseClient()
>>> client.update_user('me', '<consent hash>')
  • Parameters

  • user_id (str) – The user_id to modify consent hash for

  • consent_hash (str) – The consent_hash to set

  • Returns

    batch handle id and pre-signed upload url

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

class las.Client(credentials: Optional[las.credentials.Credentials] = None)

Bases: las.client.BaseClient

A high level client to invoke api methods from Lucidtech AI Services.

DEFAULT_BATCH_ID( = 'default')

Create a prediction on a document specified by path using specified model. This method takes care of creating and uploading a document specified by document_path. as well as running inference using model specified by model_name to create prediction on the document.

>>> from las import Client
>>> client = Client()
>>> client.predict(document_path='document.jpeg', model_name='invoice')
  • Parameters

  • document_path (str) – Path to document to run inference on

  • model_name (str) – The name of the model to use for inference

  • consent_id (str) – An identifier to mark the owner of the document handle

  • extras (Dict[str, Any**]) – Extra information to add to json body

  • Returns

    Prediction on document

  • Return type

    Prediction

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

send_feedback(document_id: str, feedback: List[las.prediction.Field])

Send feedback to the model. This method takes care of sending feedback related to document specified by document_id. Feedback consists of ground truth values for the document specified as a list of Field instances.

>>> from las import Client
>>> client = Client()
>>> feedback = [Field(label='total_amount', value='120.00'), Field(label='purchase_date', value='2019-03-10')]
>>> client.send_feedback('<document id>', feedback)
  • Parameters

  • document_id (str) – The document id of the document that will receive the feedback

  • feedback (List[Field**]) – A list of Field representing the ground truth values for the document

  • Returns

    Feedback response

  • Return type

    dict

  • Raises

    InvalidCredentialsException, TooManyRequestsException, LimitExceededException, requests.exception.RequestException

class las.Credentials(client_id: str, client_secret: str, api_key: str, auth_endpoint: str, api_endpoint: str)

Bases: object

Used to fetch and store credentials and to generate/cache an access token.

  • Parameters

  • client_id – The client id

  • client_secret – The client secret

  • api_key – The api key

  • auth_endpoint – The auth endpoint

  • api_endpoint – The api endpoint

property access_token()

override_with_environ()

Replaces all values in self with those defined in environ.

Bases: dict, typing.Generic

property document_id()

property fields()

property model_name()

class las.Field(label: str, value: str, confidence=None)

Bases: dict, typing.Generic

property confidence()

property label()

property value()