Skip to main content

Official Python SDK for KeiroLabs API - Search, Research, and Web Crawling

Project description

KeiroLabs Python SDK

Official Python SDK for the KeiroLabs API - providing easy access to search, research, and web crawling capabilities.

PyPI version Python Support License: MIT

🚀 Installation

pip install keirolabs

📖 Quick Start

from keirolabs import Keiro

# Initialize the client
client = Keiro(api_key="your-api-key-here")

# Perform a basic search (costs 1 credit)
result = client.search("What is machine learning?")
print(result['data'])
print(f"Credits remaining: {result['creditsRemaining']}")

# Get a detailed answer (costs 5 credits)
answer = client.answer("Explain quantum computing in simple terms")
print(answer['data'])

# Perform research
research = client.research("Latest developments in AI")
print(research)

🔧 Configuration

Production Server (Default)

The SDK automatically uses the production server - no configuration needed!

from keirolabs import Keiro

# That's it! Production server is automatic
client = Keiro(api_key="your-api-key")

Local Development (Optional)

Only specify base_url if you're running a local development server:

# For local development only
client = Keiro(
    api_key="your-api-key",
    base_url="http://localhost:8000/api"
)

Environment Variables (Recommended)

import os
from keirolabs import Keiro

# Production (base_url is automatic)
client = Keiro(api_key=os.getenv("KEIRO_API_KEY"))

# Or for local development
client = Keiro(
    api_key=os.getenv("KEIRO_API_KEY"),
    base_url="http://localhost:8000/api"  # Only for local dev
)

Create a .env file:

KEIRO_API_KEY=your-api-key-here
# KEIRO_BASE_URL only needed for local development

Load it using python-dotenv:

pip install python-dotenv
from dotenv import load_dotenv
import os
from keirolabs import Keiro

load_dotenv()
client = Keiro(api_key=os.getenv("KEIRO_API_KEY"))

📚 API Reference

Search APIs

search(query, **kwargs)

Perform basic search operation.

  • Cost: 1 credit
  • Args:
    • query (str): Search query
    • **kwargs: Additional parameters
  • Returns: Dict with search results and credits remaining
result = client.search("Python programming tutorials")

search_pro(query, **kwargs)

Advanced search with Pro features.

result = client.search_pro("Advanced Python concepts")

search_engine(query, **kwargs)

Use the search engine functionality.

result = client.search_engine("Best Python libraries 2024")

Answer API

answer(query, **kwargs)

Generate detailed answers to questions.

  • Cost: 5 credits
  • Args:
    • query (str): Question to answer
    • **kwargs: Additional parameters
  • Returns: Dict with answer and credits remaining
answer = client.answer("How does blockchain work?")

Research APIs

research(query, **kwargs)

Perform research on a topic.

research = client.research("Climate change solutions")

research_pro(query, **kwargs)

Advanced research with Pro features.

research = client.research_pro("Advanced AI research papers")

Web Crawler API

web_crawler(url, **kwargs)

Crawl and extract data from websites.

data = client.web_crawler("https://example.com")

Utility Methods

health_check()

Check API health status.

health = client.health_check()
print(health)

set_base_url(base_url)

Update the base URL.

client.set_base_url("https://api.keiro.com/api")

🛡️ Error Handling

The SDK provides specific exception classes for different error scenarios:

from keirolabs import Keiro
from keirolabs.exceptions import (
    KeiroAuthError,
    KeiroRateLimitError,
    KeiroValidationError,
    KeiroConnectionError,
    KeiroAPIError,
)

client = Keiro(api_key="your-api-key")

try:
    result = client.search("test query")
except KeiroAuthError:
    print("Invalid API key")
except KeiroRateLimitError:
    print("Out of credits")
except KeiroValidationError as e:
    print(f"Validation error: {e}")
except KeiroConnectionError as e:
    print(f"Connection failed: {e}")
except KeiroAPIError as e:
    print(f"API error: {e}")

Exception Types

  • KeiroError: Base exception for all SDK errors
  • KeiroAuthError: Invalid API key or authentication failure
  • KeiroRateLimitError: Out of credits or rate limit exceeded
  • KeiroValidationError: Invalid request parameters
  • KeiroConnectionError: Network or connection issues
  • KeiroAPIError: General API errors

🔐 Context Manager

Use the SDK with context manager for automatic cleanup:

with Keiro(api_key="your-api-key") as client:
    result = client.search("query")
    print(result)
# Session automatically closed

⚙️ Advanced Usage

Custom Timeout

client = Keiro(
    api_key="your-api-key",
    timeout=60  # 60 seconds timeout
)

Passing Additional Parameters

# All methods accept **kwargs for additional parameters
result = client.search(
    query="Python",
    custom_param="value",
    another_param=123
)

📝 Examples

Example 1: Basic Search and Answer

from keirolabs import Keiro

client = Keiro(api_key="your-api-key")

# Search for information
search_result = client.search("Best practices for Python")
print("Search Results:", search_result['data'])

# Get detailed answer
answer = client.answer("What are Python decorators?")
print("Answer:", answer['data'])
print(f"Credits Used: {answer['creditsRemaining']}")

Example 2: Web Crawling

from keirolabs import Keiro

client = Keiro(api_key="your-api-key")

# Crawl a website
crawl_data = client.web_crawler("https://example.com")
print("Crawled Data:", crawl_data)

Example 3: Error Handling

from keirolabs import Keiro
from keirolabs.exceptions import KeiroRateLimitError, KeiroAuthError

client = Keiro(api_key="your-api-key")

try:
    results = []
    queries = ["query1", "query2", "query3"]
    
    for query in queries:
        result = client.search(query)
        results.append(result)
        
except KeiroRateLimitError:
    print("Ran out of credits! Please add more credits to continue.")
except KeiroAuthError:
    print("Authentication failed. Check your API key.")

🧪 Testing

Create a test file to verify your setup:

# test_keiro.py
from keirolabs import Keiro
import os

def test_sdk():
    # Uses production server by default
    client = Keiro(api_key=os.getenv("KEIRO_API_KEY"))
    
    # Test health check
    health = client.health_check()
    print("✓ Health check passed:", health)
    
    # Test search
    result = client.search("test query")
    print("✓ Search passed:", result)
    
    print("\n✅ All tests passed!")

if __name__ == "__main__":
    test_sdk()

📦 Requirements

  • Python >= 3.7
  • requests >= 2.28.0

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

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

🔗 Links

💬 Support

For support, email support@keiro.com or open an issue on GitHub.

📋 Changelog

Version 0.1.0 (Initial Release)

  • ✅ Basic search functionality
  • ✅ Answer generation
  • ✅ Research capabilities
  • ✅ Web crawler
  • ✅ Comprehensive error handling
  • ✅ Environment-aware base URL configuration
  • ✅ Context manager support

Made with ❤️ by the KeiroLabs Team

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

keirolabs-0.1.1.tar.gz (13.8 kB view details)

Uploaded Source

Built Distribution

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

keirolabs-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file keirolabs-0.1.1.tar.gz.

File metadata

  • Download URL: keirolabs-0.1.1.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for keirolabs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8394e7dfb35e6ad7ea1999ae1f7c84c3317e0b955ece8816d9bc25b5c844b6ad
MD5 50eac453e29338057439081a22b356a9
BLAKE2b-256 67de57ca91e352cf3a80c56c091fc0eb00238e1389b9dc44f123fe8a62c14082

See more details on using hashes here.

File details

Details for the file keirolabs-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: keirolabs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for keirolabs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3e0b6d5b3b1187c4f0392ac1d5a7880bed8ec258e87d764fb6e46297599dfc2
MD5 639b568ff3fbac8416f5e6d1bc6db7ef
BLAKE2b-256 6a58a622aa22c0a9cd6e8d49d076878a35d9a3a00e2c97e00e73d2ffc66ba7b1

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