Skip to main content

Official Python SDK for Llama Search AI Platform

Project description

Llama Search Python SDK

The official Python SDK for the Llama Search AI Platform. This SDK provides a simple, intuitive interface for integrating AI-powered web search capabilities into your applications.

Installation

pip install llama-search

Quick Start

Async Usage (Recommended)

from llama_search import AsyncLlamaSearch

async def main():
    async with AsyncLlamaSearch(api_key="your_api_key_here") as client:
        # Perform a web search
        result = await client.web_search(
            query="Tesla Model 3 battery specifications",
            search_depth="standard"
        )

        print(f"Found {len(result.sources)} sources")
        for source in result.sources:
            print(f"- {source.url}: {source.content[:100]}...")

        # Check account usage
        stats = await client.get_usage_stats()
        print(f"Credits remaining: {stats.credits_remaining}")
        print(f"Total searches: {stats.total_searches}")

import asyncio
asyncio.run(main())

Sync Usage

from llama_search import LlamaSearch

with LlamaSearch(api_key="your_api_key_here") as client:
    # Perform a web search
    result = client.web_search(
        query="Tesla Model 3 battery specifications",
        search_depth="standard"
    )

    print(f"Found {len(result.sources)} sources")
    for source in result.sources:
        print(f"- {source.url}: {source.content[:100]}...")

    # Check account usage
    stats = client.get_usage_stats()
    print(f"Credits remaining: {stats.credits_remaining}")
    print(f"Total searches: {stats.total_searches}")

API Reference

Core Search Methods

web_search(query, search_depth="standard", domain="", with_full_content=False)

Perform intelligent web search using AI.

Parameters:

  • query (str): The search query to execute
  • search_depth (str): Search depth level affecting cost and quality
    • "basic": 5 credits, 2 tool calls, low context
    • "standard": 8 credits, 3 tool calls, medium context (default)
    • "extensive": 15 credits, 5 tool calls, high context
  • domain (str): Optional domain filter (e.g., "reddit.com")
  • with_full_content (bool): Whether to fetch full content from URLs

Returns: WebSearchResult containing sources and metadata

result = await client.web_search("Python asyncio best practices", search_depth="extensive")
print(f"Credits consumed: {result.credits_consumed}")

get_search_types()

Get available search types and their costs.

Returns: SearchTypesResponse containing available search types

types = await client.get_search_types()
for search_type in types.search_types:
    print(f"{search_type.name}: {search_type.credits} credits")

Account Management

get_usage_stats()

Get current usage statistics for your account.

Returns: UsageStats containing search counts, credits used/remaining, monthly usage

stats = await client.get_usage_stats()
print(f"Credits remaining: {stats.credits_remaining}")
print(f"Searches this month: {stats.searches_this_month}")
print(f"Total searches: {stats.total_searches}")

get_search_history(limit=10)

Get your recent search history.

Parameters:

  • limit (int): Maximum number of searches to return (1-100, default: 10)

Returns: SearchHistory containing list of recent searches

history = await client.get_search_history(limit=20)
for search in history.searches:
    print(f"{search.created_at}: {search.query} ({search.credits_consumed} credits)")

Billing Information

get_credit_packages()

Get available credit packages for purchase.

Returns: CreditPackagesResponse containing available packages

packages = await client.get_credit_packages()
for package in packages.packages:
    print(f"{package.name}: {package.credits} credits for {package.price_display}")

get_purchase_history(limit=10)

Get your credit purchase history.

Parameters:

  • limit (int): Maximum number of purchases to return (1-50, default: 10)

Returns: PurchaseHistory containing purchase records and totals

history = await client.get_purchase_history()
print(f"Total spent: ${history.total_spent_cents / 100:.2f}")
for purchase in history.purchases:
    print(f"{purchase.created_at}: {purchase.package_name} - {purchase.credits} credits")

Error Handling

The SDK provides specific exceptions for different error scenarios:

from llama_search._exceptions import (
    InsufficientCreditsError,
    ValidationError,
    AuthenticationError,
    RateLimitError
)

try:
    result = await client.web_search("example query")
except InsufficientCreditsError as e:
    print(f"Need {e.credits_required} credits, have {e.credits_available}")
except ValidationError as e:
    print(f"Invalid request: {e}")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after} seconds")

Requirements

  • Python 3.10+
  • httpx >= 0.24.0
  • pydantic >= 2.0.0

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
make test

# Run tests with coverage
pytest --cov=llama_search

Code Quality

# Format code
make format

# Lint code
make lint

# Type checking
make typecheck

License

MIT License - see LICENSE file for details.

Support

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

llama_search-0.3.3.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

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

llama_search-0.3.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file llama_search-0.3.3.tar.gz.

File metadata

  • Download URL: llama_search-0.3.3.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llama_search-0.3.3.tar.gz
Algorithm Hash digest
SHA256 c25db548ea9a9c5992ec5f57e2feb6a5243c28fc40f6459f81d4a7644d28e0ec
MD5 524aa1ec970fbcc6964c17b860fe7d23
BLAKE2b-256 a22a635722107829f69bd6c84fa3dc0540efe5273c77cfbd94c50f030d7dfffb

See more details on using hashes here.

File details

Details for the file llama_search-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: llama_search-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for llama_search-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 621f5f2dabf7bb559554871eb8abc9a62e65dcdb478d8f36f62a221dbc68c0cc
MD5 aac205a885099aa16e0403ed0d0ff6c8
BLAKE2b-256 15f2f4a35cd7231b212313f531eea1d8db2b4245540fda41723945ebf0caf902

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