sema4ai-di-client


Namesema4ai-di-client JSON
Version 1.0.13 PyPI version JSON
download
home_pagehttps://github.com/Sema4AI/document-intelligence-client
SummarySema4AI Document Intelligence API client
upload_time2025-01-06 17:04:25
maintainerNone
docs_urlNone
authorSukeesh V.
requires_python<4.0,>=3.10
licenseSema4.ai Proprietary (see LICENSE)
keywords openapi openapi-generator document intelligence api
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Document Intelligence Client

This Python package offers a robust client for seamless interaction with the Document Intelligence API. It enables you to efficiently retrieve, manage, and process document data within your workspace.

## Installation

To install the package directly from GitHub using `pip`, run the following command:

```sh
pip install sema4ai-di-client
```

## Usage

After installing the package, you can import it and start using the `DocumentIntelligenceClient` class.

### Importing the Package

```python
from sema4ai.di_client import DocumentIntelligenceClient
```

### Getting a Document Work Item

To retrieve a document work item, make sure you've set the required environment variables before initializing the client. Specifically, ensure that `DOCUMENT_INTELLIGENCE_SERVICE_URL` and `AGENTS_EVENTS_SERVICE_URL` is set.

When running in Sema4.ai Control Room these are all handled by the platform.

- **Environment Variables:** Make sure the required environment variables (`DOCUMENT_INTELLIGENCE_SERVICE_URL`, `AGENTS_EVENTS_SERVICE_URL`) are set in your environment before running the code.
- **Workspace ID:** If you are developing on local, then make sure to set workspace_id in `DocumentIntelligenceClient(workspace_id='<your_workspace_id>')`, which is optional and deduced on non-local environments from the URL passed.
- **Initialize the Client:** The client will automatically read the environment variables and initialize the connection.
- **Error Handling:** The example includes error handling and ensures the client is properly closed at the end.

Here's an example:

```python
from sema4ai.di_client import DocumentIntelligenceClient

# Ensure environment variables are set for the service URLs
# Example:
# export DOCUMENT_INTELLIGENCE_SERVICE_URL='https://api.yourdomain.com'
# export AGENTS_EVENTS_SERVICE_URL='https://agents.yourdomain.com'

# Initialize the client
client = DocumentIntelligenceClient()

# Specify the document ID you want to retrieve
document_id = 'your_document_id'

# Get the document work item
try:
    document_work_item = client.get_document_work_item(document_id)
    if document_work_item:
        print("Document Work Item:")
        print(document_work_item)
    else:
        print("No document work item found for the given document ID.")
except Exception as e:
    print(f"An error occurred: {e}")
finally:
    client.close()  # Make sure to close the client connection
```

### Available Methods

The `DocumentIntelligenceClient` offers several methods to interact with the Document Intelligence API and manage work items. Below are examples of the available operations:

- **Get Document Type:** Retrieve details about a specific document type.

  ```python
  document_type = client.get_document_type(document_type_name)
  ```

- **Get Document Format:** Fetch the format of a document based on its type and class.

  ```python
  document_format = client.get_document_format(document_type_name, document_class_name)
  ```

- **Store Extracted Content:** Store extracted content after processing a document.

  ```python
  client.store_extracted_content(extracted_content)
  ```

- **Store Transformed Content:** Save content that has been transformed by a process.

  ```python
  client.store_transformed_content(transformed_content)
  ```

- **Store Computed Content:** Submit content that has been computed after analysis.

  ```python
  client.store_computed_content(computed_content)
  ```

- **Get Document Content:** Retrieve document content in various states, such as raw, extracted, transformed, or computed.

  ```python
  content = client.get_document_content(document_id, content_state)
  ```

- **Remove Document Content:** Delete content for a document in a specific state.

  ```python
  client.remove_document_content(document_id, content_state)
  ```

- **Complete Work Item Stage:** Mark a work item’s current stage as complete and move to the next stage.

  ```python
  response = client.work_items_complete_stage(
      work_item_id='your_work_item_id',
      status='SUCCESS',  # or 'FAILURE'
      status_reason='optional_reason',  # Optional
      log_details_path='optional_log_path'  # Optional
  )
  ```

## Dependencies

The package requires the following dependencies:

- `urllib3 >= 1.25.3, < 2.1.0`
- `python-dateutil`
- `pydantic >= 2`
- `typing-extensions >= 4.7.1`

These should be installed automatically when you install the package via `pip`.

### Example Code Snippet

Below is an example code snippet if you are testing on prod.

```python
from sema4ai.di_client import DocumentIntelligenceClient

client = DocumentIntelligenceClient()

# Fetch and print the document type
try:
    document_type = client.get_document_type("CounterParty Reconciliation")
    print(document_type)
except Exception as e:
    print(f"An error occurred: {e}")
finally:
    client.close()  # Ensure proper resource cleanup
```

Below is an example code snippet if you are testing on local.

```python
from sema4ai.di_client import DocumentIntelligenceClient
import os

# Set the required environment variables within the Python code
os.environ['DOCUMENT_INTELLIGENCE_SERVICE_URL'] = 'http://127.0.0.1:9080'
os.environ['AGENTS_EVENTS_SERVICE_URL'] = 'http://127.0.0.1:9080'

workspace_id = "<your Sema4.ai Control Room Workspace ID>"
client = DocumentIntelligenceClient(workspace_id=workspace_id)

# Fetch and print the document type
try:
    document_type = client.get_document_type("CounterParty Reconciliation")
    print(document_type)
except Exception as e:
    print(f"An error occurred: {e}")
finally:
    client.close()  # Ensure proper resource cleanup
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Sema4AI/document-intelligence-client",
    "name": "sema4ai-di-client",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "OpenAPI, OpenAPI-Generator, Document Intelligence API",
    "author": "Sukeesh V.",
    "author_email": "sukeesh@sema4.ai",
    "download_url": "https://files.pythonhosted.org/packages/27/2c/9ba7647584a1d5cfca7aec1491102671eefa0889e19ef3a30db423aac62c/sema4ai_di_client-1.0.13.tar.gz",
    "platform": null,
    "description": "# Document Intelligence Client\n\nThis Python package offers a robust client for seamless interaction with the Document Intelligence API. It enables you to efficiently retrieve, manage, and process document data within your workspace.\n\n## Installation\n\nTo install the package directly from GitHub using `pip`, run the following command:\n\n```sh\npip install sema4ai-di-client\n```\n\n## Usage\n\nAfter installing the package, you can import it and start using the `DocumentIntelligenceClient` class.\n\n### Importing the Package\n\n```python\nfrom sema4ai.di_client import DocumentIntelligenceClient\n```\n\n### Getting a Document Work Item\n\nTo retrieve a document work item, make sure you've set the required environment variables before initializing the client. Specifically, ensure that `DOCUMENT_INTELLIGENCE_SERVICE_URL` and `AGENTS_EVENTS_SERVICE_URL` is set.\n\nWhen running in Sema4.ai Control Room these are all handled by the platform.\n\n- **Environment Variables:** Make sure the required environment variables (`DOCUMENT_INTELLIGENCE_SERVICE_URL`, `AGENTS_EVENTS_SERVICE_URL`) are set in your environment before running the code.\n- **Workspace ID:** If you are developing on local, then make sure to set workspace_id in `DocumentIntelligenceClient(workspace_id='<your_workspace_id>')`, which is optional and deduced on non-local environments from the URL passed.\n- **Initialize the Client:** The client will automatically read the environment variables and initialize the connection.\n- **Error Handling:** The example includes error handling and ensures the client is properly closed at the end.\n\nHere's an example:\n\n```python\nfrom sema4ai.di_client import DocumentIntelligenceClient\n\n# Ensure environment variables are set for the service URLs\n# Example:\n# export DOCUMENT_INTELLIGENCE_SERVICE_URL='https://api.yourdomain.com'\n# export AGENTS_EVENTS_SERVICE_URL='https://agents.yourdomain.com'\n\n# Initialize the client\nclient = DocumentIntelligenceClient()\n\n# Specify the document ID you want to retrieve\ndocument_id = 'your_document_id'\n\n# Get the document work item\ntry:\n    document_work_item = client.get_document_work_item(document_id)\n    if document_work_item:\n        print(\"Document Work Item:\")\n        print(document_work_item)\n    else:\n        print(\"No document work item found for the given document ID.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    client.close()  # Make sure to close the client connection\n```\n\n### Available Methods\n\nThe `DocumentIntelligenceClient` offers several methods to interact with the Document Intelligence API and manage work items. Below are examples of the available operations:\n\n- **Get Document Type:** Retrieve details about a specific document type.\n\n  ```python\n  document_type = client.get_document_type(document_type_name)\n  ```\n\n- **Get Document Format:** Fetch the format of a document based on its type and class.\n\n  ```python\n  document_format = client.get_document_format(document_type_name, document_class_name)\n  ```\n\n- **Store Extracted Content:** Store extracted content after processing a document.\n\n  ```python\n  client.store_extracted_content(extracted_content)\n  ```\n\n- **Store Transformed Content:** Save content that has been transformed by a process.\n\n  ```python\n  client.store_transformed_content(transformed_content)\n  ```\n\n- **Store Computed Content:** Submit content that has been computed after analysis.\n\n  ```python\n  client.store_computed_content(computed_content)\n  ```\n\n- **Get Document Content:** Retrieve document content in various states, such as raw, extracted, transformed, or computed.\n\n  ```python\n  content = client.get_document_content(document_id, content_state)\n  ```\n\n- **Remove Document Content:** Delete content for a document in a specific state.\n\n  ```python\n  client.remove_document_content(document_id, content_state)\n  ```\n\n- **Complete Work Item Stage:** Mark a work item\u2019s current stage as complete and move to the next stage.\n\n  ```python\n  response = client.work_items_complete_stage(\n      work_item_id='your_work_item_id',\n      status='SUCCESS',  # or 'FAILURE'\n      status_reason='optional_reason',  # Optional\n      log_details_path='optional_log_path'  # Optional\n  )\n  ```\n\n## Dependencies\n\nThe package requires the following dependencies:\n\n- `urllib3 >= 1.25.3, < 2.1.0`\n- `python-dateutil`\n- `pydantic >= 2`\n- `typing-extensions >= 4.7.1`\n\nThese should be installed automatically when you install the package via `pip`.\n\n### Example Code Snippet\n\nBelow is an example code snippet if you are testing on prod.\n\n```python\nfrom sema4ai.di_client import DocumentIntelligenceClient\n\nclient = DocumentIntelligenceClient()\n\n# Fetch and print the document type\ntry:\n    document_type = client.get_document_type(\"CounterParty Reconciliation\")\n    print(document_type)\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    client.close()  # Ensure proper resource cleanup\n```\n\nBelow is an example code snippet if you are testing on local.\n\n```python\nfrom sema4ai.di_client import DocumentIntelligenceClient\nimport os\n\n# Set the required environment variables within the Python code\nos.environ['DOCUMENT_INTELLIGENCE_SERVICE_URL'] = 'http://127.0.0.1:9080'\nos.environ['AGENTS_EVENTS_SERVICE_URL'] = 'http://127.0.0.1:9080'\n\nworkspace_id = \"<your Sema4.ai Control Room Workspace ID>\"\nclient = DocumentIntelligenceClient(workspace_id=workspace_id)\n\n# Fetch and print the document type\ntry:\n    document_type = client.get_document_type(\"CounterParty Reconciliation\")\n    print(document_type)\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    client.close()  # Ensure proper resource cleanup\n```\n",
    "bugtrack_url": null,
    "license": "Sema4.ai Proprietary (see LICENSE)",
    "summary": "Sema4AI Document Intelligence API client",
    "version": "1.0.13",
    "project_urls": {
        "Homepage": "https://github.com/Sema4AI/document-intelligence-client",
        "Repository": "https://github.com/Sema4AI/document-intelligence-client"
    },
    "split_keywords": [
        "openapi",
        " openapi-generator",
        " document intelligence api"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3239b0477388c0431616b859f0df0611f6c17f2763e78052edcd8ef961e327b3",
                "md5": "d1d8195940b0f18cb8ac5da4b4ba53b5",
                "sha256": "98a47556fb4caa9ad22fa8cd7c94d341a0c7df9d064a0251743d243080587014"
            },
            "downloads": -1,
            "filename": "sema4ai_di_client-1.0.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d1d8195940b0f18cb8ac5da4b4ba53b5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 147597,
            "upload_time": "2025-01-06T17:04:24",
            "upload_time_iso_8601": "2025-01-06T17:04:24.107626Z",
            "url": "https://files.pythonhosted.org/packages/32/39/b0477388c0431616b859f0df0611f6c17f2763e78052edcd8ef961e327b3/sema4ai_di_client-1.0.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "272c9ba7647584a1d5cfca7aec1491102671eefa0889e19ef3a30db423aac62c",
                "md5": "54e5a6462c920351ba425a2d1a66b5f5",
                "sha256": "a67ca009c9dea1494b204c924856c9b24c92730dd69abde0e4de2ccf9c0d8615"
            },
            "downloads": -1,
            "filename": "sema4ai_di_client-1.0.13.tar.gz",
            "has_sig": false,
            "md5_digest": "54e5a6462c920351ba425a2d1a66b5f5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 72633,
            "upload_time": "2025-01-06T17:04:25",
            "upload_time_iso_8601": "2025-01-06T17:04:25.431744Z",
            "url": "https://files.pythonhosted.org/packages/27/2c/9ba7647584a1d5cfca7aec1491102671eefa0889e19ef3a30db423aac62c/sema4ai_di_client-1.0.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-06 17:04:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Sema4AI",
    "github_project": "document-intelligence-client",
    "github_not_found": true,
    "lcname": "sema4ai-di-client"
}
        
Elapsed time: 0.56801s