Sample Script
This tutorial will show you the basics of how to use the Composio SDK to call tools.
SAMPLE
$ pip install composio
Here’s a complete Python example that demonstrates the Composio SDK:
Setting up Composio and OpenAI
1 from composio_core import Composio 2 from openai import OpenAI 3 4 # Initialize OpenAI client 5 openai = OpenAI( 6 api_key="your-openai-api-key" 7 ) 8 9 # Initialize Composio client 10 composio = Composio( 11 api_key="your-composio-api-key" 12 ) 13 14 # Set up user identifier 15 userId = "your@email.com" 16 17 # Authorize and get tools for Gmail 18 connection, tools = composio.toolkits.authorize(userId, "gmail") 19 print(f"🔗 Visit the URL to authorize:\n👉 {connection.redirect_url}") 20 21 # Wait for the user to complete authorization 22 connection.wait_for_connection() 23 24 # Create a chat completion with tool calling 25 completion = openai.chat.completions.create( 26 model="gpt-4o", 27 messages=[ 28 { 29 "role": "system", 30 "content": "You are a helpful assistant that can send emails.", 31 }, 32 { 33 "role": "user", 34 "content": "send an email to sid@composio.dev saying 'hi from the composio quickstart'", 35 # we'll ship you free merch if you do ;) 36 }, 37 ], 38 tools=tools, 39 tool_choice="auto", 40 ) 41 42 # Handle the tool call and execute 43 result = composio.provider.handle_tool_call(userId, completion) 44 print("✅ Email sent successfully!") 45 print(result)