Skip to main content

Official Python SDK for Pivota Agent API

Project description

Pivota Agent SDK for Python

Official Python SDK for integrating AI agents with the Pivota e-commerce platform.

🚀 Quick Start

Installation

pip install pivota-agent-sdk

Get API Key

from pivota_agent import PivotaAgentClient

# Create agent and get API key
client = PivotaAgentClient.create_agent(
    agent_name="MyShoppingBot",
    agent_email="bot@mycompany.com",
    description="AI shopping assistant"
)

print(f"Your API key: {client.api_key}")
# Save this key securely!

Initialize with API Key

client = PivotaAgentClient(api_key="ak_live_your_key_here")

📚 Usage Examples

1. Search Products

# Search across all merchants
products = client.search_products(
    query="gaming laptop",
    max_price=1500,
    limit=10
)

for product in products["products"]:
    print(f"{product['name']} - ${product['price']} - {product['merchant_name']}")

2. Create Order

# Create order
order = client.create_order(
    merchant_id="merch_xxx",
    items=[
        {"product_id": "prod_123", "quantity": 1},
        {"product_id": "prod_456", "quantity": 2}
    ],
    customer_email="buyer@example.com",
    shipping_address={
        "street": "123 Main St",
        "city": "San Francisco",
        "state": "CA",
        "zip": "94105",
        "country": "US"
    }
)

print(f"Order created: {order['order_id']}")
print(f"Total: ${order['total_amount']}")

3. Process Payment

# Create payment
payment = client.create_payment(
    order_id=order["order_id"],
    payment_method={
        "type": "card",
        "token": "tok_visa_test"  # From Stripe/Adyen
    },
    return_url="https://mybot.com/payment-callback"
)

if payment["status"] == "requires_action":
    # Handle 3DS
    print(f"Redirect user to: {payment['next_action']['redirect_url']}")
elif payment["status"] == "succeeded":
    print("Payment successful!")

4. Track Order

# Get order status
order_status = client.get_order(order_id="order_xxx")

print(f"Status: {order_status['status']}")
print(f"Tracking: {order_status.get('tracking_number')}")

🔧 Advanced Features

Error Handling

from pivota_agent import AuthenticationError, RateLimitError, NotFoundError

try:
    products = client.search_products(query="laptop")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except NotFoundError:
    print("Resource not found")
except PivotaAPIError as e:
    print(f"API error: {e.message} (status: {e.status_code})")

Pagination

# Get all products with pagination
all_products = []
offset = 0
limit = 50

while True:
    result = client.search_products(
        query="shoes",
        limit=limit,
        offset=offset
    )
    
    all_products.extend(result["products"])
    
    if not result["pagination"]["has_more"]:
        break
    
    offset += limit

print(f"Total products found: {len(all_products)}")

List Merchants

# Get all available merchants
merchants = client.list_merchants(status="active", limit=100)

for merchant in merchants:
    print(f"{merchant['business_name']} - {merchant['status']}")
    if merchant['mcp_connected']:
        print(f"  Platform: {merchant['mcp_platform']}")
    if merchant['psp_connected']:
        print(f"  PSP: {merchant['psp_type']}")

📖 API Reference

PivotaAgentClient

Constructor

PivotaAgentClient(
    api_key: str = None,
    base_url: str = "https://web-production-fedb.up.railway.app/agent/v1",
    timeout: int = 30
)

Methods

Method Description Returns
create_agent(name, email, desc) Create agent and get API key PivotaAgentClient
health_check() Check API health Dict
list_merchants(status, limit, offset) List merchants List[Dict]
search_products(query, **filters) Search products Dict
create_order(merchant_id, items, email) Create order Dict
get_order(order_id) Get order status Dict
list_orders(filters) List orders Dict
create_payment(order_id, payment_method) Create payment Dict
get_payment(payment_id) Get payment status Dict
get_analytics_summary() Get analytics Dict

🔒 Rate Limits

  • Standard tier: 1,000 requests per minute
  • Burst: Up to 50 requests in first 10 seconds

Rate limit headers included in responses:

  • X-RateLimit-Limit: Total limit
  • X-RateLimit-Remaining: Remaining requests
  • X-RateLimit-Reset: Reset timestamp

🆘 Support

📄 License

MIT License - see LICENSE file 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

pivota_agent-1.0.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

pivota_agent-1.0.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pivota_agent-1.0.0.tar.gz.

File metadata

  • Download URL: pivota_agent-1.0.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pivota_agent-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bc188b9c7d5e2c65f7f3d2d04488c284b536970ad818a2b6c92ccc9c95301a33
MD5 27b58aa5db46a6fd588150c323a49d77
BLAKE2b-256 e9b2e2914a75548742a17096a76e59cb26df46c08aabcd024bba3e0b6929b27f

See more details on using hashes here.

File details

Details for the file pivota_agent-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pivota_agent-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pivota_agent-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0439c96b88b8863ccfa69d4124755d53cd31cafc6bdbddd9710dd19008e80850
MD5 1a73f7cca18e2db52881edd3063c1724
BLAKE2b-256 ee67ad824cab8d433af1bf0c490198135373fc5684f399daf94da577c4ad92d6

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