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

Using with Different Environments

# Development (localhost)
client = Keiro(
    api_key="your-api-key",
    base_url="http://localhost:8000/api"
)

# Production
client = Keiro(
    api_key="your-api-key",
    base_url="https://keiro-production.up.railway.app/api"
)

# Or update dynamically
client.set_base_url("https://keiro-production.up.railway.app/api")

Environment Variables

You can also use environment variables in your application:

import os
from keirolabs import Keiro

api_key = os.getenv("KEIRO_API_KEY")
base_url = os.getenv("KEIRO_BASE_URL", "http://localhost:8000/api")

client = Keiro(api_key=api_key, base_url=base_url)

Create a .env file in your project:

KEIRO_API_KEY=your-api-key-here
KEIRO_BASE_URL=http://localhost:8000/api

And load it using python-dotenv:

pip install python-dotenv
from dotenv import load_dotenv
load_dotenv()

import os
from keirolabs import Keiro

client = Keiro(
    api_key=os.getenv("KEIRO_API_KEY"),
    base_url=os.getenv("KEIRO_BASE_URL")
)

📚 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():
    client = Keiro(
        api_key=os.getenv("KEIRO_API_KEY"),
        base_url="http://localhost:8000/api"
    )
    
    # 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.0.tar.gz (13.7 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.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: keirolabs-0.1.0.tar.gz
  • Upload date:
  • Size: 13.7 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.0.tar.gz
Algorithm Hash digest
SHA256 70c74ec2e3dc0578d5070ef9ea1e2e97348a359ddf73773f998e7f3a0d230aeb
MD5 0a434b22bc8a99106d1a70fe6c26af4c
BLAKE2b-256 c1a31f96f6c976a8bf355d851867ff69e382bcc51c8838ff946b944e5cb0b21c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: keirolabs-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e1a709b16df64858260deb386971b93177a1e9f431bbc7753ccdcf9b4bc0ebd
MD5 e13ee00fef38da755700b633d8191bc8
BLAKE2b-256 d7cd24cbd12d5fecd2acde8db7c1a1ca6abecb2982e32c983b7ca803f34ca0ee

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