Skip to main content

Stateless API Mapping Context for LLM Tooling - Python SDK

Project description

ApiToolBox Python SDK

Stateless API Mapping Context for LLM Tooling - Python SDK

Overview

ApiToolBox provides a unified interface for loading and managing API service definitions, making it easy to integrate various APIs into LLM applications. This Python SDK is designed for server-side usage and provides async support for efficient API operations.

Installation

pip install pleom-apitoolbox

Quick Start

Basic Usage

import asyncio
from pleom_apitoolbox import ApiToolBox, User, ServiceConfig

async def main():
    # Initialize ApiToolBox
    api_toolbox = ApiToolBox()
    
    # Load services
    await api_toolbox.load_services(['vercel', 'github'])
    
    # List available services
    services = api_toolbox.get_services()
    print(f"Loaded services: {services}")
    
    # List available tools
    tools = await api_toolbox.list_tools(model='openai')
    print(f"Available tools: {len(tools)}")

if __name__ == "__main__":
    asyncio.run(main())

Making Authenticated API Calls

import asyncio
from pleom_apitoolbox import ApiToolBox, User, ServiceConfig

async def main():
    # Initialize ApiToolBox and load services
    api_toolbox = ApiToolBox()
    await api_toolbox.load_services(['vercel'])
    
    # Configure service authentication
    service_configs = [
        ServiceConfig('vercel', {
            'Authorization': 'Bearer your-vercel-token'
        })
    ]
    
    # Create user instance
    user = User(api_toolbox, service_configs)
    
    # Find a specific tool
    tool = api_toolbox.find_tool_by_id('vercelRetrieveAListOfProjects')
    if tool:
        print(f"Found tool: {tool['name']}")
        
        # Call the tool
        try:
            result = await user.call_tool('vercelRetrieveAListOfProjects')
            print(f"API Response: {result}")
        except Exception as e:
            print(f"Error calling tool: {e}")

if __name__ == "__main__":
    asyncio.run(main())

Tool Format Examples

# Get tools in different formats
tools_openai = await api_toolbox.list_tools(model='openai')
tools_claude = await api_toolbox.list_tools(model='claude') 
tools_gemini = await api_toolbox.list_tools(model='gemini')

# Raw tools (unformatted)
raw_tools = await api_toolbox.list_tools(filter_tools=False)

API Reference

ApiToolBox

Main class for managing API services and tools.

Methods

  • get_services() -> List[str]: Get list of loaded services
  • list_tools(model='gemini', filter_tools=True) -> List[Dict]: Get formatted tools
  • find_tool_by_id(tool_id: str) -> Optional[Dict]: Find tool by ID
  • load_services(services: List[str], force_download=False): Load services
  • unload_service(service_name: str): Unload a service

User

Class for making authenticated API calls.

Methods

  • call_tool(tool_id: str, parameters=None) -> Dict: Call an API tool
  • validate_tool_call(tool_id: str, response) -> bool: Validate API response
  • get_config() -> Dict: Get current configuration
  • update_config(config: Dict): Update configuration

ServiceConfig

Configuration for API services.

config = ServiceConfig('service_name', {
    'Authorization': 'Bearer token',
    'apiKey': 'your-api-key',
    # ... other headers/config
})

Development

Setup Development Environment

git clone https://github.com/pleom/apitoolbox.git
cd apitoolbox
pip install -e ".[dev]"

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=pleom_apitoolbox --cov-report=html

# Run specific test
pytest tests/test_api_toolbox.py

Code Formatting

# Format code
black pleom_apitoolbox/
isort pleom_apitoolbox/

# Type checking
mypy pleom_apitoolbox/

# Linting
flake8 pleom_apitoolbox/

Testing Your Installation

Create a test script:

# test_installation.py
import asyncio
from pleom_apitoolbox import ApiToolBox

async def test_basic_functionality():
    print("Testing ApiToolBox...")
    
    # Test basic initialization
    api_toolbox = ApiToolBox()
    print("✓ ApiToolBox initialized successfully")
    
    # Test getting services (should be empty initially)
    services = api_toolbox.get_services()
    print(f"✓ Services: {services}")
    
    # Test listing tools (should be empty initially)
    tools = await api_toolbox.list_tools()
    print(f"✓ Tools: {len(tools)} tools found")
    
    print("✓ All tests passed!")

if __name__ == "__main__":
    asyncio.run(test_basic_functionality())

Run the test:

python test_installation.py

Deployment to PyPI

Prerequisites

  1. Install build tools:
pip install build twine
  1. Create PyPI account and get API token

Building the Package

# Clean previous builds
rm -rf dist/ build/ *.egg-info/

# Build the package
python -m build

Upload to PyPI

# Upload to Test PyPI first
twine upload --repository testpypi dist/*

# Test installation from Test PyPI
pip install --index-url https://test.pypi.org/simple/ pleom-apitoolbox

# Upload to production PyPI
twine upload dist/*

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite
  6. Submit a pull request

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

pleom_apitoolbox-1.0.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

pleom_apitoolbox-1.0.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file pleom_apitoolbox-1.0.1.tar.gz.

File metadata

  • Download URL: pleom_apitoolbox-1.0.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for pleom_apitoolbox-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ddfb165e682d216368185d156479b3ac6003ca513b77d22a1408e9dd9d0c0617
MD5 723a0f61eea0af1679cf0e174923bd58
BLAKE2b-256 7f98859aee336f62ea07881c26c1400848d4e83e2a95dfd61df95dec9b07f9c1

See more details on using hashes here.

File details

Details for the file pleom_apitoolbox-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pleom_apitoolbox-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b9ebb338f7e21d3be265c9adcc216760172b7fb1421322728e1a2e8c9e969d4
MD5 e25e08c49507c1ac32bcba72a315715a
BLAKE2b-256 a2a7bdce408908379d5a3f0e479cf1c334e130252e6e063f8f96ae7b1bce3e0b

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