-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56a85fc
commit 928dbc1
Showing
26 changed files
with
579 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from mindee import Client, WorkflowResponse | ||
from mindee.parsing.common import ExecutionPriority | ||
|
||
# Init a new client | ||
mindee_client = Client(api_key: "my-api-key") | ||
|
||
workflow_id = "workflow-id" | ||
|
||
# Load a file from disk | ||
input_doc = mindee_client.source_from_path("/path/to/the/file.ext") | ||
|
||
# Send the file to the workflow. | ||
result: WorkflowResponse = mindee_client.execute_workflow( | ||
input_doc, | ||
workflow_id, | ||
# Optionally, add an alias and a priority to the workflow. | ||
# alias="my-alias", | ||
# priority=ExecutionPriority.LOW | ||
) | ||
|
||
# Print the ID of the execution to make sure it worked. | ||
print(result.execution.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
PathInput, | ||
UrlInputSource, | ||
) | ||
from mindee.input.workflow_options import WorkflowOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Optional | ||
|
||
from mindee.parsing.common import ExecutionPriority | ||
|
||
|
||
class WorkflowOptions: | ||
"""Options to pass to a workflow execution.""" | ||
|
||
alias: Optional[str] | ||
"""Alias for the document.""" | ||
priority: Optional[ExecutionPriority] | ||
"""Priority of the document.""" | ||
full_text: bool | ||
"""Whether to include the full OCR text response in compatible APIs.""" | ||
public_url: Optional[str] | ||
"""A unique, encrypted URL for accessing the document validation interface without requiring authentication.""" | ||
|
||
def __init__( | ||
self, | ||
alias: Optional[str] = None, | ||
priority: Optional[ExecutionPriority] = None, | ||
full_text: Optional[bool] = False, | ||
public_url: Optional[str] = None, | ||
): | ||
self.alias = alias | ||
self.priority = priority | ||
self.full_text = full_text if full_text else False | ||
self.public_url = public_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import os | ||
from dataclasses import dataclass | ||
from typing import Dict, Optional, Union | ||
|
||
from mindee.logger import logger | ||
from mindee.versions import __version__, get_platform, python_version | ||
|
||
API_KEY_ENV_NAME = "MINDEE_API_KEY" | ||
API_KEY_DEFAULT = "" | ||
|
||
BASE_URL_ENV_NAME = "MINDEE_BASE_URL" | ||
BASE_URL_DEFAULT = "https://api.mindee.net/v1" | ||
|
||
REQUEST_TIMEOUT_ENV_NAME = "MINDEE_REQUEST_TIMEOUT" | ||
TIMEOUT_DEFAULT = 120 | ||
|
||
PLATFORM = get_platform() | ||
USER_AGENT = f"mindee-api-python@v{__version__} python-v{python_version} {PLATFORM}" | ||
|
||
|
||
@dataclass | ||
class BaseSettings: | ||
"""Settings class relating to API requests.""" | ||
|
||
api_key: Optional[str] | ||
"""API Key for the client.""" | ||
base_url: str | ||
request_timeout: int | ||
|
||
def __init__(self, api_key: Optional[str]): | ||
self._set_api_key(api_key) | ||
self.request_timeout = TIMEOUT_DEFAULT | ||
self.set_base_url(BASE_URL_DEFAULT) | ||
self.set_from_env() | ||
|
||
@property | ||
def base_headers(self) -> Dict[str, str]: | ||
"""Base headers to send with all API requests.""" | ||
return { | ||
"Authorization": f"Token {self.api_key}", | ||
"User-Agent": USER_AGENT, | ||
} | ||
|
||
def _set_api_key(self, api_key: Optional[str]) -> None: | ||
"""Set the endpoint's API key from an environment variable, if present.""" | ||
env_val = os.getenv(API_KEY_ENV_NAME, "") | ||
if env_val and (not api_key or len(api_key) == 0): | ||
logger.debug("API key set from environment") | ||
self.api_key = env_val | ||
return | ||
self.api_key = api_key | ||
|
||
def set_from_env(self) -> None: | ||
"""Set various parameters from environment variables, if present.""" | ||
env_vars = { | ||
BASE_URL_ENV_NAME: self.set_base_url, | ||
REQUEST_TIMEOUT_ENV_NAME: self.set_timeout, | ||
} | ||
for name, func in env_vars.items(): | ||
env_val = os.getenv(name, "") | ||
if env_val: | ||
func(env_val) | ||
logger.debug("Value was set from env: %s", name) | ||
|
||
def set_timeout(self, value: Union[str, int]) -> None: | ||
"""Set the timeout for all requests.""" | ||
self.request_timeout = int(value) | ||
|
||
def set_base_url(self, value: str) -> None: | ||
"""Set the base URL for all requests.""" | ||
self.base_url = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.