FastAPI extension for creating Broccoli tools from API endpoints with one click in Swagger UI
Project description
Broccoli Tool Creator
A FastAPI extension that automatically creates tools in the Broccoli platform from your API endpoints with a single click in Swagger UI.
Features
- 🚀 One-Click Tool Creation: Create Broccoli tools directly from Swagger UI
- 🔄 Smart Sync: Automatically detects existing tools and switches between Create/Update modes
- 🔐 Automatic Authentication: Uses AWS Cognito SRP for seamless authentication
- 🎯 AST-Based Extraction: Intelligently extracts endpoint metadata from your code
- 💾 Persistent Tracking: Tracks created tools in your database (SQLite or PostgreSQL)
- 🌐 Proxy Support: Access Broccoli tools through an authenticated proxy
Installation
pip install broccoli-tool-creator
Quick Start
1. Configure in your FastAPI app
from fastapi import FastAPI
from broccoli_tool_creator import setup_tool_creator, ToolCreatorConfig
app = FastAPI(docs_url=None) # Disable default docs
# Configure tool creator
config = ToolCreatorConfig(
broccoli_api_url="https://your-broccoli-backend.com",
cognito_client_id="your-client-id",
cognito_username="your-username",
cognito_password="your-password",
cognito_pool_id="your-pool-id",
owner_id="your-user-id",
tool_tracking_db_url="postgresql://user:pass@localhost/db" # Optional
)
# Setup tool creator (includes custom /docs)
setup_tool_creator(app, config)
2. Use in Swagger UI
- Navigate to
/docs - Find any endpoint
- Click "Create Tool" or "Update Tool" button
- Click "Go to Tools" to view in Broccoli
Configuration
Required Settings
ToolCreatorConfig(
broccoli_api_url="https://broccoli-backend.com", # Broccoli API URL
cognito_client_id="...", # AWS Cognito Client ID
cognito_username="...", # Cognito username
cognito_password="...", # Cognito password
cognito_pool_id="...", # Cognito Pool ID (region_poolId)
owner_id="...", # Broccoli user ID
)
Optional Settings
ToolCreatorConfig(
...,
tool_tracking_db_url="postgresql://...", # External database (default: SQLite)
)
Database & Persistence
By default, the tool creator uses a local SQLite database (created_tools.db) to track which tools have been created. This allows the UI to show "Update Tool" instead of "Create Tool" for existing tools.
Using External Database
To use PostgreSQL or another database:
from app.core.config import settings
config = ToolCreatorConfig(
...,
tool_tracking_db_url=settings.DATABASE_URL
)
Docker Configuration
When running in Docker, ensure your DATABASE_URL uses the correct hostname:
# .env file
DATABASE_URL=postgresql://user:pass@postgres:5432/dbname
The postgres hostname works for inter-container communication when using docker-compose.
Features
Dynamic UI Buttons
The Swagger UI automatically shows context-aware buttons:
- "Create Tool" (Green) - For endpoints without tools
- "Update Tool" (Orange) - For endpoints with existing tools
- "Go to Tools" (Blue) - Opens the tool in Broccoli with automatic authentication
Smart Version Handling
The system automatically handles version conflicts:
- Detects version mismatches from the Broccoli API
- Automatically retries with the correct version
- No manual intervention required
Authenticated Proxy
Access Broccoli tools through your backend with automatic authentication:
/api/v1/dev-tools/view-tool/{tool_id}
This endpoint:
- Authenticates using your Cognito credentials
- Redirects to the Broccoli tool view page
- Proxies all requests with proper authentication headers
API Endpoints
The package adds these endpoints to your FastAPI app:
POST /api/v1/dev-tools/create-from-endpoint- Create/update a toolGET /api/v1/dev-tools/check-tools- Get list of existing toolsGET /api/v1/dev-tools/view-tool/{tool_id}- View tool with authenticationGET /api/v1/dev-tools/broccoli-proxy/{path:path}- Proxy to Broccoli
Requirements
- Python 3.8+
- FastAPI 0.100.0+
- SQLAlchemy 1.4.0+
- httpx 0.24.0+
- pycognito 2024.5.1+
License
MIT License
Support
For issues and questions, please open an issue on GitHub.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file broccoli_tool_creator-0.1.1.tar.gz.
File metadata
- Download URL: broccoli_tool_creator-0.1.1.tar.gz
- Upload date:
- Size: 24.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85954384d447adb3cc176976c6c6e85a5309f7b18f05a1ab5c6df9f61ed0978f
|
|
| MD5 |
d2ea0f49db82eea803f69117b71ff5cb
|
|
| BLAKE2b-256 |
1163a63129385ed6b096aaccf01cfdea0dbe17e95dc34a9fd9ef155d09a6eeed
|
File details
Details for the file broccoli_tool_creator-0.1.1-py3-none-any.whl.
File metadata
- Download URL: broccoli_tool_creator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 33.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1976fb4a827633b9a11b95e4316cc21b3d5e012be931b7668bb6ee38061f6920
|
|
| MD5 |
694ad07497ebc7ee83655d5eaf09dad1
|
|
| BLAKE2b-256 |
461e8711dd0931a8a5a1432222c5f0656dfadfa33329cdaa706109cfe985304a
|