Models

Explore our complete list of models and API references here.

Prerequisites

Before you begin, you’ll need:

The SDK is compatible with Python 3.7+ and works on all major operating systems (Windows, macOS, and Linux).

Installation

Install the JigsawStack Python SDK using pip:

pip install jigsawstack

Authentication

There are two ways to authenticate with the JigsawStack API:

Set your API key as an environment variable:

# Linux/macOS
export JIGSAWSTACK_API_KEY='your-api-key'

# Windows (Command Prompt)
set JIGSAWSTACK_API_KEY=your-api-key

# Windows (PowerShell)
$env:JIGSAWSTACK_API_KEY = 'your-api-key'

Or in your project’s .env file:

.env
JIGSAWSTACK_API_KEY='your-api-key'

Then initialize the SDK without explicitly providing the API key:

from jigsawstack import JigsawStack

jigsawstack = JigsawStack()  # API key will be read from environment

Option 2: Direct Initialization

Provide your API key directly when initializing the SDK:

from jigsawstack import JigsawStack

jigsawstack = JigsawStack(api_key="your-api-key")

Basic Usage

Here’s a quick example of using the AI web scraper to extract information from an Amazon product page:

from jigsawstack import JigsawStack

# Initialize the SDK
jigsawstack = JigsawStack()  # API key from environment variables

# Define parameters for web scraping
params = {
    "url": "https://www.amazon.com/Cadbury-Mini-Caramel-Eggs-Bulk/dp/B0CWM99G5W",
    "element_prompts": ["prices", "title", "ratings", "product_details"]
}

# Make the API call
result = jigsawstack.web.ai_scrape(params)

# Print the results
print(f"Product Title: {result.get('title')}")
print(f"Price Information: {result.get('prices')}")

Response Handling

JigsawStack returns structured data as Python dictionaries. Here’s how to handle the response:

# Example response handling
try:
    result = jigsawstack.web.ai_scrape(params)
    
    # Access nested data
    if "prices" in result:
        current_price = result["prices"].get("current_price")
        print(f"Current Price: ${current_price}")
    
    # Iterate through multiple results
    if "product_details" in result:
        print("Product Details:")
        for key, value in result["product_details"].items():
            print(f"- {key}: {value}")
            
except Exception as e:
    print(f"Error: {e}")

More Examples

Sentiment Analysis

sentiment_result = jigsawstack.ai.sentiment({
    "text": "I absolutely love this product! It's amazing!"
})
print(f"Sentiment: {sentiment_result.get('sentiment')}")
print(f"Score: {sentiment_result.get('score')}")

Text Translation

translation = jigsawstack.ai.translate({
    "text": "Hello, world!",
    "target_language": "es"  # Spanish
})
print(f"Translated text: {translation.get('translated_text')}")

Text to Speech

speech = jigsawstack.audio.text_to_speech({
    "text": "Welcome to JigsawStack Python SDK!",
    "voice": "en-US-female"
})

# Save the audio to a file
with open("welcome_message.mp3", "wb") as audio_file:
    audio_file.write(speech.content)

Next Steps

Now that you’ve set up the JigsawStack Python SDK, you can:

Start building powerful AI applications with JigsawStack today!