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():
api_toolbox = ApiToolBox()
await api_toolbox.load_services(['vercel', 'github'])
services = api_toolbox.get_services()
print(f"Loaded services: {services}")
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():
api_toolbox = ApiToolBox()
await api_toolbox.load_services(['vercel'])
service_configs = [
ServiceConfig('vercel', {
'Authorization': 'Bearer your-vercel-token'
})
]
user = User(api_toolbox, service_configs)
tool = api_toolbox.find_tool_by_id('vercelRetrieveAListOfProjects')
if tool:
print(f"Found tool: {tool['name']}")
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
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 = 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',
})
Development
Setup Development Environment
git clone https://github.com/pleom/apitoolbox.git
cd apitoolbox
pip install -e ".[dev]"
Running Tests
pytest
pytest --cov=pleom_apitoolbox --cov-report=html
pytest tests/test_api_toolbox.py
Code Formatting
black pleom_apitoolbox/
isort pleom_apitoolbox/
mypy pleom_apitoolbox/
flake8 pleom_apitoolbox/
Testing Your Installation
Create a test script:
import asyncio
from pleom_apitoolbox import ApiToolBox
async def test_basic_functionality():
print("Testing ApiToolBox...")
api_toolbox = ApiToolBox()
print("✓ ApiToolBox initialized successfully")
services = api_toolbox.get_services()
print(f"✓ Services: {services}")
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
pip install build twine
- Create PyPI account and get API token
Building the Package
rm -rf dist/ build/ *.egg-info/
python -m build
Upload to PyPI
twine upload --repository testpypi dist/*
pip install --index-url https://test.pypi.org/simple/ pleom-apitoolbox
twine upload dist/*
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Run the test suite
- Submit a pull request
Support