-
Notifications
You must be signed in to change notification settings - Fork 6
✨ add support for workflows #274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
baebce8
:sparkles: add support for workflows
sebastianMindee 2772020
add hook notification
sebastianMindee 75a213c
fix cyclic import
sebastianMindee 8f41a0a
fix env var location
sebastianMindee dd9ae3e
add exports to init
sebastianMindee cc1e30b
fix syntax
sebastianMindee 509e090
add public url parameter to workflows
sebastianMindee 37ab31a
apply suggestions
sebastianMindee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.