Skip to main content

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

  1. Navigate to /docs
  2. Find any endpoint
  3. Click "Create Tool" or "Update Tool" button
  4. 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:

  1. Authenticates using your Cognito credentials
  2. Redirects to the Broccoli tool view page
  3. 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 tool
  • GET /api/v1/dev-tools/check-tools - Get list of existing tools
  • GET /api/v1/dev-tools/view-tool/{tool_id} - View tool with authentication
  • GET /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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

broccoli_tool_creator-0.1.0.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

broccoli_tool_creator-0.1.0-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file broccoli_tool_creator-0.1.0.tar.gz.

File metadata

  • Download URL: broccoli_tool_creator-0.1.0.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

Hashes for broccoli_tool_creator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1e42845f75f285d6b94c69bf301b915df58fe31f34dc5c8d0f16ed73d0a74a76
MD5 6d5e1a2e28d370824efa27a25b4dc5cc
BLAKE2b-256 14ff52bb3fb8de00c2eb1c684334ec5c94473518c638d43f7926a51f77e3f067

See more details on using hashes here.

File details

Details for the file broccoli_tool_creator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for broccoli_tool_creator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 637ba64c405091cc08933d38e610b12ad4ef9c188d693b85509038875fdcf225
MD5 75b45c76c2a3329607d2dfc40407f24f
BLAKE2b-256 23cc37e020dbb5cf5c54153a2fc0f9e23cbfde55037e3e97f3066d1f0f7de4ec

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