Skip to main content

Python SDK for the AgentMesh agentic commerce infrastructure

Project description

Synchronity Python SDK

PyPI version PyPI downloads License: MIT

Python SDK for the Synchronity agentic commerce infrastructure — makes any e-commerce site transactable by autonomous AI agents via authenticated REST APIs.

Installation

pip install synchronity-sdk

Or with dev dependencies for testing:

pip install "synchronity-sdk[dev]"

Quickstart

import asyncio
from agentmesh import SynchronityClient, SynchronityConfig

async def main():
    config = SynchronityConfig(agent_token="your-agent-token")

    async with SynchronityClient(config) as client:
        # Search products on a site
        results = await client.products.search("site_abc123", q="laptop", in_stock=True)
        print(results["products"])

        # Create a cart and add an item
        cart = await client.cart.create("site_abc123", currency="USD")
        cart = await client.cart.add_item("site_abc123", cart.cart_id, "prod_42", quantity=1)

        # Apply a coupon
        cart = await client.cart.apply_coupon("site_abc123", cart.cart_id, "SAVE10")

        # Execute checkout
        from agentmesh import ShippingAddressParams
        order = await client.checkout.execute(
            site_id="site_abc123",
            cart_id=cart.cart_id,
            buyer_delegation_token="buyer-token-from-auth-flow",
            shipping_address=ShippingAddressParams(
                name="Jane Smith",
                line1="123 Main St",
                city="San Francisco",
                state="CA",
                postal_code="94102",
                country="US",
            ),
        )
        print(order.order_id, order.status)

asyncio.run(main())

Tools for LLM Frameworks

The SDK ships ready-to-use tool definitions for Anthropic, OpenAI, and LangChain.

Anthropic

from agentmesh.tools import anthropic_tools, ToolExecutor
from agentmesh import SynchronityClient, SynchronityConfig
import anthropic

client = SynchronityClient(SynchronityConfig(agent_token="your-token"))
executor = ToolExecutor(client)

anthropic_client = anthropic.Anthropic()
response = anthropic_client.messages.create(
    model="claude-opus-4-5",
    max_tokens=1024,
    tools=anthropic_tools,
    messages=[{"role": "user", "content": "Find me a red laptop under $1000 on site site_abc123"}],
)

# Execute tool calls
import asyncio
for block in response.content:
    if block.type == "tool_use":
        result = asyncio.run(executor.execute(block.name, block.input))
        print(result)

OpenAI

from agentmesh.tools import openai_tools, ToolExecutor
from openai import OpenAI

openai_client = OpenAI()
response = openai_client.chat.completions.create(
    model="gpt-4o",
    tools=openai_tools,
    messages=[{"role": "user", "content": "Search for laptops on site_abc123"}],
)

LangChain

from agentmesh.tools import langchain_tools
# langchain_tools is a list of dicts with name, description, and schema

Available Tools (11)

Tool Description
search_products Search products on a site with filters
get_product Get full product details by ID
compare_products Compare products across multiple sites
create_cart Create a new shopping cart
add_to_cart Add a product/variant to a cart
remove_from_cart Remove a line item from a cart
apply_coupon Apply a discount code to a cart
get_cart Get current cart contents
execute_checkout Execute checkout and return a confirmed order
get_order Get order details by ID
list_orders List orders with optional status filter

Configuration

from agentmesh import SynchronityConfig

config = SynchronityConfig(
    agent_token="your-agent-token",   # required
    base_url="https://agentmesh-production.up.railway.app",  # default
    timeout=30.0,    # seconds
    retries=3,       # auto-retry on 429 and 5xx
    retry_delay=1.0, # base delay for exponential backoff
)

Error Handling

from agentmesh.errors import (
    AuthenticationError,   # 401
    AuthorizationError,    # 403
    NotFoundError,         # 404 / 410
    ValidationError,       # 400
    RateLimitError,        # 429 — has .retry_after attribute
    ConnectorError,        # 422
    NetworkError,          # network failures
    TimeoutError,          # request timeout
    SynchronityError,        # base class
)

try:
    product = await client.products.get_by_id("site_abc", "prod_999")
except NotFoundError as e:
    print(f"Product not found: {e.code}")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")

Running Tests

pip install -e ".[dev]"
pytest tests/ -v

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

synchronity_sdk-0.2.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

synchronity_sdk-0.2.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file synchronity_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: synchronity_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for synchronity_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 bd25186bb1bdc55f44f6128c5118f6bb5e0ed1af1430f6f5ff0b9c12d7bb0be4
MD5 45e6b28cdf6694a85417553c8ebd80da
BLAKE2b-256 f24ecac8b2a370e4a9c07caf7f77a50c7468bc28e931fcefffd0128d0eb40b65

See more details on using hashes here.

File details

Details for the file synchronity_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for synchronity_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5f304d2171448c96b04195941ee53d807c2714d0ae596c584986ca918ef5fd6e
MD5 7da28a00dca0657415c268f1cb2f063f
BLAKE2b-256 6dd5928eec6d3dd4f3b51c015cd7be22234e688be8b5f59b670fb31c6d8f0d79

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