pica-langchain on PyPI
Install the Python SDK to unlock powerful tools for LangChain
Prerequisites
Before installing ToolKit, you’ll need:- Pica Account - Free account for managing integrations
- Pica API Key - API key from your Pica dashboard
- LangChain - Installed in your Python project
- LLM Provider - API key from OpenAI, Anthropic, or your chosen provider
Installation
Install the Pica LangChain SDK:Quick Start
1
Set environment variables
Configure your API keys as environment variables:
2
Connect integrations
Go to the Connections page and connect integrations (e.g., Gmail, Slack, Salesforce). You’ll need at least one connection for your agent to interact with.
3
Create your first agent
Create a LangChain agent with Pica tools:
Configuration
PicaClientOptions
Configure the Pica client with these options:URL for self-hosted Pica server. Use this if you’re running your own instance of Pica.
List of connection keys to filter by. Pass
["*"]
to initialize all available connections, or specify exact connection keys. If empty, no connections will be initialized.List of action IDs to filter by. Set to
["*"]
for all actions, or specify individual action IDs from the available actions table.Permission level to filter actions by:
"read"
- Only GET requests (read-only access)"write"
- POST, PUT, PATCH requests (create/update operations)"admin"
- All HTTP methods including DELETE
Filter connections by a specific identifier (e.g., user ID, team ID). Use with
identity_type
for multi-tenant applications.Filter connections by identity type. Works with the
identity
parameter.If
True
, the SDK will use AuthKit to prompt users to connect platforms they don’t currently have access to.create_pica_agent
Customize agent creation with these parameters:Initialized Pica client instance. Must be created and initialized before passing to the agent.
LangChain LLM to use for the agent. Can be any LangChain-compatible language model.
Type of LangChain agent to create. See LangChain documentation for available types.
Whether to print verbose logs during agent execution.
Custom system prompt to append to the default Pica system prompt.
Additional LangChain tools to include alongside Pica tools.
Whether to return the intermediate steps of the agent execution.
Usage Patterns
Basic Agent
The simplest setup with full access to integrations:Streaming Response
Enable streaming for real-time output:Example
With AuthKit
Enable AuthKit to prompt users to connect missing integrations:Example
Multi-Tenant Agent
Filter connections by user identity:Example
Example Workflows
- GitHub Workflow
- Airtable to GitHub
- Sheets to Gmail
Star a GitHub repository and list your starred repos:
Example
Logging
The Pica LangChain SDK uses Python’slogging
module. Set the log level using the PICA_LOG_LEVEL
environment variable:
debug
- Detailed debugging informationinfo
- General information messageswarning
- Warning messageserror
- Error messagescritical
- Critical error messages
Best Practices
Use specific connections in production
Use specific connections in production
Instead of
connectors=["*"]
, specify exact connection keys for better performance:Set appropriate permissions
Set appropriate permissions
Use permission levels based on your use case:
"read"
- For data retrieval agents"write"
- For agents that create/update data"admin"
- For full-access automation (use carefully)
Handle multi-tenancy
Handle multi-tenancy
Always filter by identity in multi-user applications:
Monitor usage
Monitor usage
Track API usage in your Pica dashboard and view request logs at Logs.
Troubleshooting
No connections available
No connections available
Problem: Agent reports no connections available.Solutions:
- Verify you’ve connected integrations in the Pica dashboard
- Check that
connectors
is set correctly (use["*"]
for all) - If using
identity
, ensure the identity value matches your connections
Actions not executing
Actions not executing
Problem: Agent finds actions but can’t execute them.Solutions:
- Ensure connections have proper authentication
- Check
permissions
level allows the required HTTP method - Verify the connection hasn’t expired (re-authenticate if needed)
- Check for error messages in the agent’s response
Authentication errors
Authentication errors
Problem: Getting 401 or authentication errors.Solutions:
- Verify
PICA_SECRET
environment variable is set correctly - Check API key is valid at Settings > API Keys
- Ensure integrations are properly connected