Skip to main content

Manifest-driven workflow execution SDK for HashImport

Project description

hashimportai

Python SDK for executing HashImport workflows using hashlets.

Installation

pip install hashimportai

For development or to install from source, see PUBLISHING.md.

Quick Start

Complete Example with Subscribers

import asyncio
from hashimportai import WorkflowRunner

# Define subscriber callbacks for each action
def on_vault_linker(action_name, response):
    print(f"[Subscriber] {action_name} completed: {response}")

def on_upload_pdf(action_name, response):
    print(f"[Subscriber] {action_name} completed: {response}")
    if response and response.get("data"):
        result = response.get("data", {}).get("result", {})
        if isinstance(result, dict) and "linked_output" in result:
            print(f"  -> Uploaded file: {result['linked_output']}")

def on_esign_pdf(action_name, response):
    print(f"[Subscriber] {action_name} completed: {response}")

def on_esign_signed_url(action_name, response):
    print(f"[Subscriber] {action_name} completed: {response}")
    if response and response.get("data"):
        result = response.get("data", {}).get("result", {})
        if isinstance(result, dict) and "url" in result:
            print(f"  -> Signed URL: {result['url']}")

# Create subscribers dictionary mapping action names to callbacks
subscribers = {
    "vault_linker": on_vault_linker,
    "upload_pdf": on_upload_pdf,
    "esign_pdf": on_esign_pdf,
    "esign_signed_url": on_esign_signed_url,
}

async def main():
    # Option 1: Pass credentials directly (recommended)
    runner = WorkflowRunner(
        workflow_id="69576bd6af6515a54826291c",
        multi_part_actions=["upload_pdf"],
        subscribers=subscribers,
        api_key="your-api-key",
        base_url="http://localhost:6003/api/v1"
    )
    
    form_data = {
        "vault_linker": {"hashlet_id": "694d1e4bb731610cf532267b"},
        "upload_pdf": {"file": "tmp/document.pdf"},  # Relative to current working directory
        "esign_pdf": {
            "filename": "is_link",  # Will be auto-populated from upload_pdf output
            "creator_id": "1234567890",
            "purpose": "test",
            "email": "john.doe@example.com",
            "company_full_name": "John Doe",
            "location": "123 Main St, Anytown, USA",
            "sig_x1": 100,
            "sig_y1": 100,
            "sig_x2": 200,
            "sig_y2": 200,
            "sign_page": 1,
        },
        "esign_signed_url": {"filename": "document.pdf"},
    }
    
    await runner.run("hashhub-fc77bf01", form_data)

asyncio.run(main())

Option 2: Use Environment Variables

export HASHIMPORTAI_API_KEY="your-api-key"
export HASHIMPORTAI_BASE_URL="http://localhost:6003/api/v1"
import asyncio
from hashimportai import WorkflowRunner

async def main():
    # Credentials loaded from environment variables
    runner = WorkflowRunner(
        workflow_id="your-workflow-id",
        multi_part_actions=["upload_pdf"],
        subscribers=subscribers  # Optional: can be None or empty dict
    )
    
    form_data = {
        "upload_pdf": {"file": "document.pdf"}
    }
    
    await runner.run("hashhub-xxx", form_data)

asyncio.run(main())

Configuration

API Key and Base URL

You can provide credentials in two ways:

  1. Direct parameters (recommended for scripts):

    runner = WorkflowRunner(
        workflow_id="...",
        multi_part_actions=["..."],
        api_key="your-api-key",
        base_url="http://localhost:6003/api/v1"
    )
    
  2. Environment variables (recommended for production):

    export HASHIMPORTAI_API_KEY="your-api-key"
    export HASHIMPORTAI_BASE_URL="http://localhost:6003/api/v1"
    

Subscribers (Callbacks)

Subscribers allow you to handle responses from each action:

subscribers = {
    "action_name": lambda action, response: print(f"{action} completed: {response}")
}

Each callback receives:

  • action_name: The name of the action that completed
  • response: The response data from the action execution

File Paths

File paths in form_data are resolved relative to your current working directory, not the SDK directory:

  • {"file": "document.pdf"} → looks for ./document.pdf in your current directory
  • {"file": "tmp/document.pdf"} → looks for ./tmp/document.pdf in your current directory
  • {"file": "/absolute/path/to/file.pdf"} → uses absolute path as-is

Auto-linking Actions

Use "is_link" as a value to automatically link outputs between actions:

form_data = {
    "upload_pdf": {"file": "document.pdf"},
    "esign_pdf": {
        "filename": "is_link",  # Will be replaced with output from upload_pdf
        # ... other fields
    }
}

The SDK automatically extracts the linked_output from the previous action and replaces "is_link" with the actual filename.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hashimportai-0.1.1.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hashimportai-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file hashimportai-0.1.1.tar.gz.

File metadata

  • Download URL: hashimportai-0.1.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for hashimportai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dc2bf6a08ce8f993d171df53f37606a79cf9f8577461c743aa0a993cf5ef6401
MD5 0987082e4742135292a4eb78e1a8cbf0
BLAKE2b-256 8b62bde57835ceb5c75477d6b41df2a21550e2a146fd4295658f7d9160693c35

See more details on using hashes here.

File details

Details for the file hashimportai-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hashimportai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for hashimportai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6f59ccd24f5c949e334e38efa1461c84321eb14548db67671117a27cf4f93333
MD5 f1af90e40ed1dac268f00e944d59f8f9
BLAKE2b-256 2d6643affa64abf99c839173ff622fd23aea2e5953a57a6ff823dcb9156d0488

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page