RPA.DocumentAI
module RPA.DocumentAI
class RPA.DocumentAI.DocumentAI.DocumentAI
Wrapper library offering generic keywords for initializing, scanning and retrieving results as fields from documents (PDF, PNG etc.).
Library requires at the minimum rpaframework version 19.0.0.
This is a helper facade for the following libraries:
- RPA.Cloud.Google (requires rpaframework-google)
- RPA.DocumentAI.Base64AI
- RPA.DocumentAI.Nanonets
Where the following steps are required:
- Engine initialization:
Init Engine
- Document scan:
Predict
- Result retrieval:
Get Result
So no matter the engine you’re using, the very same keywords can be used, as only
the passed parameters will differ (please check the docs on each library for
particularities). Once initialized, you can jump between the engines with
Switch Engine
. Before scanning documents, you must configure the service first,
with a model to scan the files with and an API key for authorizing the access.
See Portal example: https://robocorp.com/portal/robot/robocorp/example-document-ai
Example: Robot Framework
Example: Python
variable ROBOT_AUTO_KEYWORDS
variable ROBOT_LIBRARY_DOC_FORMAT
variable ROBOT_LIBRARY_SCOPE
property engine : Any
method get_result
Retrieve the result data previously obtained with Predict
.
The stored raw result is usually pre-processed with a library specific keyword prior the return.
- Parameters: extended – Get all the details inside the result data. (main fields only by default)
- Returns: Usually a list of fields detected in the document.
Example: Robot Framework
Example: Python
method init_engine
Initialize the engine you want to scan documents with.
This is required before being able to run Predict
. Once initialized, you
don’t need to run this again, simply use Switch Engine
to jump between
the engines. The final secret value (passed directly with secret or picked up
automatically from the Vault with vault) will be split into authorization
args and kwargs or just passed as it is to the wrapped library. Keep in mind
that some engines are expecting API keys where others tokens or private keys.
Any optional keyword argument will be passed further in the wrapped library.
Parameters
- name – Name of the engine.
- secret – Authenticate with a string/file/object secret directly.
- vault – Specify the Vault storage name and secret key in order to authenticate. (‘name:key’ or {name: key} formats are supported)
How secret resolution works
When vault is passed in, the corresponding Vault is retrieved and the value belonging to specified field is returned as a secret. If a secret is used, then this value is returned as it is if this isn’t a path pointing to the file holding the value to be returned. We’ll be relying on environment variables in the absence of both the secret and vault.
Expected secret value formats:
- google: <json-service/token> (
RPA.Cloud.Google.Init Document AI
) - base64ai: ,
(
RPA.DocumentAI.Base64AI.Set Authorization
) - nanonets: (
RPA.DocumentAI.Nanonets.Set Authorization
)
Example: Robot Framework
Example: Python
method predict
Scan a document with the currently active engine and store the result internally for a later retrieval.
Based on the selected engine, this wraps a chain of libraries until calling a service API in the end, where the passed file is analyzed. Any optional keyword argument will be passed further in the wrapped library. (some engines require mandatory parameters like project ID or region)
Parameters
- location – Path to a local file or URL address of a remote one. (not all engines work with URLs)
- model – Model name(s) to scan with. (some engines guess the model if not specified)
Example: Robot Framework
Example: Python
property result : Union[Dict[Hashable, Optional[Union[str, int, float, bool, list, dict]]], List[Optional[Union[str, int, float, bool, list, dict]]], str, int, float, bool, list, dict, None, Document]
method switch_engine
Switch between already initialized engines.
Use this to jump between engines when scanning with multiple of them.
- Parameters: name – Name of the engine to be set as active. (choose between: google, base64ai, nanonets)
Example: Robot Framework
Example: Python