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
- API Key and Agent ID: Obtain these from the Splore console.
- 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
extractionsandagent_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file splore_sdk-0.1.3.tar.gz.
File metadata
- Download URL: splore_sdk-0.1.3.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.21.0 CPython/3.13.1 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68c8c534234757325b4ada0def4c5e851b25f57ad996b16197c8c72e90557414
|
|
| MD5 |
e786c2a7721e48c83a271c34a86bb1d3
|
|
| BLAKE2b-256 |
9df92bb304efc28e6662f9d2dba43f46c118c09781caa5ce9e8e5e9f82754123
|
File details
Details for the file splore_sdk-0.1.3-py3-none-any.whl.
File metadata
- Download URL: splore_sdk-0.1.3-py3-none-any.whl
- Upload date:
- Size: 14.8 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2617c61f32609e21657f18dcfc879b091361b4497190dc4f3930827730a580d1
|
|
| MD5 |
2fd33de3dcf5391bbc4773c02d476252
|
|
| BLAKE2b-256 |
37a7b52ab3f2973810523d2dca3d61095f02409ccbfa8c5b0d91a8283fa33d41
|