Skip to main content

Amigo AI Python SDK

Project description

Amigo Python SDK

Tests codecov License: MIT

The official Python SDK for the Amigo API, providing a simple and intuitive interface to interact with Amigo's AI services.

Installation

This SDK requires Python 3.11 or newer.

Install the SDK using pip:

pip install amigo_sdk

Or add it to your requirements.txt:

amigo_sdk

API compatibility

This SDK auto-generates its types from the latest Amigo OpenAPI schema. As a result, only the latest published SDK version is guaranteed to match the current API. If you pin to an older version, it may not include the newest endpoints or fields.

Quick Start (sync)

from amigo_sdk import AmigoClient
from amigo_sdk.models import GetConversationsParametersQuery

# Initialize and use the client synchronously
with AmigoClient(
    api_key="your-api-key",
    api_key_id="your-api-key-id",
    user_id="user-id",
    organization_id="your-organization-id",
) as client:
    conversations = client.conversation.get_conversations(
        GetConversationsParametersQuery(limit=10, sort_by=["-created_at"])
    )
    print("Conversations:", conversations)

Quick Start (async)

import asyncio

from amigo_sdk import AsyncAmigoClient
from amigo_sdk.models import GetConversationsParametersQuery


async def main():
    async with AsyncAmigoClient(
        api_key="your-api-key",
        api_key_id="your-api-key-id",
        user_id="user-id",
        organization_id="your-organization-id",
    ) as client:
        conversations = await client.conversation.get_conversations(
            GetConversationsParametersQuery(limit=10, sort_by=["-created_at"])
        )
        print("Conversations:", conversations)


asyncio.run(main())

Examples

For more SDK usage examples see the examples overview. Direct links:

Configuration

The SDK requires the following configuration parameters:

Parameter Type Required Description
api_key str API key from Amigo dashboard
api_key_id str API key ID from Amigo dashboard
user_id str User ID on whose behalf the request is made
organization_id str Your organization ID
base_url str Base URL of the Amigo API (defaults to https://api.amigo.ai)

Environment Variables

You can also configure the SDK using environment variables:

export AMIGO_API_KEY="your-api-key"
export AMIGO_API_KEY_ID="your-api-key-id"
export AMIGO_USER_ID="user-id"
export AMIGO_ORGANIZATION_ID="your-organization-id"
export AMIGO_BASE_URL="https://api.amigo.ai"  # optional

Then initialize the client without parameters:

from amigo_sdk import AmigoClient

# Automatically loads from environment variables
with AmigoClient() as client:
    ...

Using .env Files

Create a .env file in your project root:

AMIGO_API_KEY=your-api-key
AMIGO_API_KEY_ID=your-api-key-id
AMIGO_USER_ID=user-id
AMIGO_ORG_ID=your-organization-id

The SDK will automatically load these variables.

Getting Your API Credentials

  1. API Key & API Key ID: Generate these from your Amigo admin dashboard or programmatically using the API
  2. Organization ID: Found in your Amigo dashboard URL or organization settings
  3. User ID: The ID of the user you want to impersonate for API calls

For detailed instructions on generating API keys, see the Authentication Guide.

Available Resources

The SDK provides access to the following resources:

  • Organizations: Get Organization info
  • Services: Get available services
  • Conversation: Manage conversations
  • User: Manage users

Generated types

The SDK ships with Pydantic models generated from the latest OpenAPI schema.

  • Importing types: Import directly from amigo_sdk.models

    from amigo_sdk.models import (
        GetConversationsParametersQuery,
        ConversationCreateConversationRequest,
        GetUsersParametersQuery,
    )
    
  • Using types when calling SDK functions: Pass request/query models to resource methods.

    from amigo_sdk import AmigoClient
    from amigo_sdk.models import GetConversationsParametersQuery
    
    with AmigoClient() as client:
       conversations = client.conversation.get_conversations(
           GetConversationsParametersQuery(limit=20, sort_by=["-created_at"])
       )
    
  • Parsing returned objects: Responses are Pydantic models. Access fields directly or convert to dict/JSON.

    # Access fields
    first = conversations.conversations[0]
    print(first.id, first.created_at)
    
    # Convert to plain dict for logging/serialization
    print(first.model_dump(mode="json"))
    

Error Handling

The SDK provides typed error handling:

from amigo_sdk import AmigoClient
from amigo_sdk.errors import (
    AuthenticationError,
    NotFoundError,
    BadRequestError,
    ValidationError,
)

try:
    with AmigoClient() as client:
        org = client.organization.get()
        print("Organization:", org)
except AuthenticationError as error:
    print("Authentication failed:", error)
except NotFoundError as error:
    print("Resource not found:", error)
except BadRequestError as error:
    print("Bad request:", error)
except ValidationError as error:
    print("Validation error:", error)
except Exception as error:
    print("Unexpected error:", error)

Retries

The HTTP client includes sensible, configurable retries:

  • Defaults:

    • max attempts: 3
    • backoff base: 0.25s (exponential with full jitter)
    • max delay per attempt: 30s
    • retry on status: {408, 429, 500, 502, 503, 504}
    • retry on methods: {"GET"}
    • special-case: POST is retried on 429 when Retry-After is present
    • 401 triggers a one-time token refresh and immediate retry

Development

For detailed development setup, testing, and contribution guidelines, see CONTRIBUTING.md.

Troubleshooting

Authentication errors

  • AuthenticationError: Invalid API key: Verify your api_key and api_key_id are correct and haven't been revoked. Regenerate them from the Amigo dashboard if needed.
  • AuthenticationError: Token expired: The SDK refreshes tokens automatically. If this persists, check that your system clock is accurate.

Configuration issues

  • ValidationError on client init: Ensure all required fields (api_key, api_key_id, user_id, organization_id) are set either as arguments or environment variables.
  • Environment variables not loading: The SDK reads from AMIGO_API_KEY, AMIGO_API_KEY_ID, AMIGO_USER_ID, and AMIGO_ORGANIZATION_ID. Check for typos and that your .env file is in the working directory.

Connection issues

  • ConnectionError or timeouts: Check your network connectivity and that https://api.amigo.ai is reachable. If you're behind a proxy, configure it via httpx proxy settings.
  • RateLimitError: The SDK retries automatically on 429 responses. If you consistently hit rate limits, reduce request frequency or contact support.

Import errors

  • ModuleNotFoundError: No module named 'amigo_sdk': Run pip install amigo_sdk. If using a virtual environment, ensure it is activated.
  • Missing model types: The SDK auto-generates types from the OpenAPI spec. Update to the latest version: pip install --upgrade amigo_sdk.

Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

For questions, issues, or feature requests, please visit our GitHub repository or contact support through the Amigo dashboard.

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

amigo_sdk-1.3.0.tar.gz (485.9 kB view details)

Uploaded Source

Built Distribution

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

amigo_sdk-1.3.0-py3-none-any.whl (117.6 kB view details)

Uploaded Python 3

File details

Details for the file amigo_sdk-1.3.0.tar.gz.

File metadata

  • Download URL: amigo_sdk-1.3.0.tar.gz
  • Upload date:
  • Size: 485.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1

File hashes

Hashes for amigo_sdk-1.3.0.tar.gz
Algorithm Hash digest
SHA256 ac8edad744d88c40ed07bfbfb32f8ad95fd12230d71dbce8bd3fd709825d40f1
MD5 51562d85e7896b61700476aa6d796755
BLAKE2b-256 112d30d94bb430d67a4ff5e91c87efb424fbbce9d90336f5446a6683228f2691

See more details on using hashes here.

File details

Details for the file amigo_sdk-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: amigo_sdk-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 117.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.5 cpython/3.13.11 HTTPX/0.28.1

File hashes

Hashes for amigo_sdk-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 773d65bc0febc52b03f66f9faf52a7c086c097ed8d0d062ace9be64888da58f5
MD5 77e0b45364669efd190c68ae9049172f
BLAKE2b-256 38212f8a52102b4f05752a72ac76d962ad390a6b924ade875011c0a7fbe0d707

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