Skip to main content

splore sdk to intract with splore services

Project description

Splore Python SDK

The Splore Python SDK simplifies the process of interacting with the Splore document processing platform. Use it to upload files, process documents, and retrieve extracted data with minimal setup.


Features

  • File Upload: Seamlessly upload documents to the processing backend.
  • Task Management: Start, monitor, and manage extraction tasks.
  • Data Retrieval: Fetch structured results after processing is completed.
  • Modular Design: Easily integrate with storage backends like AWS S3.
  • Error Handling: Get meaningful errors and retry capabilities.
  • Agent Management: Manage agents, including creation, updates, retrieval, and deletion.

Installation

Install the SDK via pip:

pip install splore-sdk

Install the SDK via pip with (optional example dependencies):

pip install splore-sdk[examples]

Quick Start

Here’s how you can use the SDK to process a file:

Prerequisites

  1. API Key and Agent ID: Obtain these from the Splore console.
  2. Python 3.7+: Ensure Python is installed on your system.

Code Example

from time import sleep
from splore_sdk import SploreSDK
import tempfile
from examples.aws import download_from_s3

# Initialize the SDK
sdk = SploreSDK(api_key="YOUR_API_KEY", base_id="YOUR_BASE_ID")

# Download the file from AWS S3
with tempfile.NamedTemporaryFile(delete=False) as tmp_file:
    s3_uri = "s3://bucket-name/path-to-file.pdf"
    download_from_s3(s3_uri, tmp_file.name)

    # fetch agents related to your base
    agents = sdk.get_agents()

    agent_id1 = agents[0]["id"] # adjust according to your response and agent you want to select
    agent_id2 = agents[1]["id"]
    extraction_agent = sdk.init_agent(agent_id = agent_id1)
    chat_agent = sdk.init_agent(agent_id = agent_id2)

    # Upload the file
    file_upload_response = extraction_agent.extractions.upload_file(tmp_file.name)
    file_id = file_upload_response.get('file_id')
    if file_id is None:
        raise RuntimeError("File upload failed!")

    # Start the extraction process
    extraction_agent.extractions.start(file_id=file_id)

    # Monitor extraction status
    while True:
        status = extraction_agent.extractions.processing_status(file_id=file_id)
        if status.get("fileProcessingStatus") == "COMPLETED":
            break
        sleep(10)  # Wait before checking again

    # Retrieve extracted data
    extracted_data = extraction_agent.extractions.extracted_response(file_id=file_id)
    print("Extracted Data:", extracted_data)

Modules Overview

SploreSDK

This is the main entry point for the SDK.

  • Initialization:
    sdk = SploreSDK(api_key="YOUR_API_KEY", agent_id="YOUR_AGENT_ID")
    
  • Provides access to extractions and agent_service.

ExtractionManager

Manage file processing and data extraction.

  • Methods:
    • upload_file(file_path: str) -> dict: Uploads a file and returns its metadata.
    • start(file_id: str) -> None: Starts the extraction process for the uploaded file.
    • processing_status(file_id: str) -> dict: Retrieves the current status of the processing task.
    • extracted_response(file_id: str) -> dict: Fetches the processed data.

AgentService

Manage agents, including creation, updates, retrieval, and deletion.

  • Methods:
    • create_agent(agent_payload: CreateAgentInput) -> dict: Creates a new agent with the specified payload.
      from splore_sdk.agents.validations import CreateAgentInput
      
      agent_payload = CreateAgentInput(agentName="Agent1", description="Sample Agent")
      response = sdk.agent_service.create_agent(agent_payload)
      print(response)
      
    • update_agent(agent_payload: UpdateAgentInput) -> dict: Updates an existing agent.
      from splore_sdk.agents.validations import UpdateAgentInput
      
      update_payload = UpdateAgentInput(agentId="123", agentName="UpdatedAgent")
      response = sdk.agent_service.update_agent(update_payload)
      print(response)
      
    • get_agents(agentId: Optional[str], agentName: Optional[str]) -> dict: Retrieves agents based on the provided criteria.
      agents = sdk.agent_service.get_agents(agentId="123", agentName=None)
      print(agents)
      
    • delete_agents(agentId: str) -> dict: Deletes the specified agent.
      response = sdk.agent_service.delete_agents(agentId="123")
      print(response)
      

AWS Integration

Easily download files from AWS S3 using:

from examples.aws import download_from_s3
download_from_s3(s3_uri, local_path)

Advanced Usage

Polling Interval Configuration

Customize the polling interval for task monitoring:

while True:
    status = sdk.extractions.processing_status(file_id=file_id)
    if status.get("fileProcessingStatus") == "COMPLETED":
        break
    sleep(5)  # Set custom polling interval

Error Handling

Handle errors gracefully:

try:
    sdk.extractions.upload_file(file_path)
except FileUploadError as e:
    print("Error uploading file:", e)

FAQ

1. How do I get an API Key?

  • Sign up on the Splore console and navigate to the API section to generate a key.

2. Can I use this SDK asynchronously?

  • Asynchronous support will be added in a future release.

3. Which file formats are supported?

  • Currently, we are supporting PDF files only.

Support

For questions or issues, please open a ticket on GitHub Issues or email us at support@splore.com.


License

This SDK is licensed under the MIT License. See LICENSE for details.

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

splore_sdk-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

splore_sdk-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file splore_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: splore_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.13.1 Darwin/23.5.0

File hashes

Hashes for splore_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b481f2ac93fa633514105841b06d5be0b69c177047739c5b3b4d85bb1d347e1
MD5 85f73c3086f4f26e1bc8b30f5c037ac8
BLAKE2b-256 1043cfb4e1d37ae5433b178246ad7652020b35f154dbcada50fcd73bba514ced

See more details on using hashes here.

File details

Details for the file splore_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: splore_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.21.0 CPython/3.13.1 Darwin/23.5.0

File hashes

Hashes for splore_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61dbaa83cfbd40282f505c9a37fc06d06a4a3567da879a42acd2fc81f95f6302
MD5 00c915586da2fee95853877e170e5204
BLAKE2b-256 6da76e03b9b89d7ad12ec6700e6a91d5c75fe6499a2fe45d13ac031a25e280a7

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