Skip to main content

Python MCP server for AI-powered image generation using Google Gemini models - A complete port of nanobanana

Project description

nanobanana-py

Python MCP server for AI-powered image generation using Google Gemini models.

A complete port of nanobanana (TypeScript) to Python.

Features

  • 7 Image Generation Tools:

    • generate_image - Text to image with styles and variations
    • edit_image - Edit existing images
    • restore_image - Restore/enhance images
    • generate_icon - App icons, favicons, UI elements
    • generate_pattern - Seamless patterns and textures
    • generate_story - Sequential story images
    • generate_diagram - Technical diagrams and flowcharts
  • Dual Model Support: Flash (fast) and Pro (high quality)

  • Auto Fallback: Automatically switches to backup model on timeout/error

  • Batch Generation: Generate multiple variations in parallel

  • Reference Images: Use existing images as references

  • Multiple Resolutions: 1K, 2K, 4K output options

Installation

Via uvx (Recommended)

uvx nanobanana-py

Via pip

pip install nanobanana-py

Via pipx

pipx install nanobanana-py

Configuration

Environment Variable

Get your API key from Google AI Studio.

export NANOBANANA_GEMINI_API_KEY="your-api-key-here"

Optional Environment Variables

# Use a different model (default: gemini-2.5-flash-image)
export NANOBANANA_MODEL="gemini-3-pro-image-preview"

# Fallback models (comma-separated, used when primary model fails)
export NANOBANANA_FALLBACK_MODELS="gemini-2.5-flash-image,gemini-2.0-flash-exp-image-generation"

# API timeout in seconds (default: 60)
export NANOBANANA_TIMEOUT="90"

# Set custom output directory
export NANOBANANA_OUTPUT_DIR="/path/to/output"

# Enable debug logging
export NANOBANANA_DEBUG="1"

Model Fallback

When the primary model fails (timeout, overload, or error), nanobanana-py automatically tries the next model in the fallback chain. The response includes fallback information:

{
  "success": true,
  "message": "Successfully generated 1 image (使用備用模型: gemini-2.5-flash-image,原本: gemini-3-pro-image-preview)",
  "modelUsed": "gemini-2.5-flash-image",
  "usedFallback": true,
  "primaryModel": "gemini-3-pro-image-preview"
}

Claude Code Integration

Add to your .mcp.json:

{
  "mcpServers": {
    "nanobanana": {
      "command": "uvx",
      "args": ["nanobanana-py"],
      "env": {
        "NANOBANANA_GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

Or with local installation:

{
  "mcpServers": {
    "nanobanana": {
      "command": "nanobanana-py"
    }
  }
}

Tools

generate_image

Generate single or multiple images from text prompts.

Parameters:

  • prompt (required): Image description
  • files: Reference image paths (1-13)
  • filename: Output filename
  • output_count: Number of variations (1-8)
  • styles: Artistic styles (photorealistic, watercolor, sketch, etc.)
  • variations: Variation types (lighting, angle, mood, etc.)
  • format: Output format (grid, separate)
  • seed: Seed for reproducibility
  • resolution: 1K, 2K, or 4K
  • preview: Auto-open in viewer

edit_image

Edit an existing image based on a text prompt.

Parameters:

  • prompt (required): Edit description
  • file (required): Input image path
  • filename: Output filename
  • resolution: 1K, 2K, or 4K
  • preview: Auto-open in viewer

restore_image

Restore or enhance an existing image.

Parameters:

  • prompt (required): Restoration description
  • file (required): Input image path
  • filename: Output filename
  • resolution: 1K, 2K, or 4K
  • preview: Auto-open in viewer

generate_icon

Generate app icons in multiple sizes.

Parameters:

  • prompt (required): Icon description
  • sizes: Icon sizes (16, 32, 64, 128, 256, 512, 1024)
  • type: app-icon, favicon, ui-element
  • style: flat, skeuomorphic, minimal, modern
  • format: png, jpeg
  • background: transparent, white, black
  • corners: rounded, sharp

generate_pattern

Generate seamless patterns and textures.

Parameters:

  • prompt (required): Pattern description
  • size: Tile size (e.g., "256x256")
  • type: seamless, texture, wallpaper
  • style: geometric, organic, abstract, floral, tech
  • density: sparse, medium, dense
  • colors: mono, duotone, colorful
  • repeat: tile, mirror

generate_story

Generate a sequence of related images.

Parameters:

  • prompt (required): Story description
  • steps: Number of images (2-8)
  • type: story, process, tutorial, timeline
  • style: consistent, evolving
  • transition: smooth, dramatic, fade

generate_diagram

Generate technical diagrams and flowcharts.

Parameters:

  • prompt (required): Diagram description
  • type: flowchart, architecture, network, database, wireframe, mindmap, sequence
  • style: professional, clean, hand-drawn, technical
  • layout: horizontal, vertical, hierarchical, circular
  • complexity: simple, detailed, comprehensive

Development

# Clone the repository
git clone https://github.com/aspect-apps/nanobanana-py.git
cd nanobanana-py

# Install dependencies
uv sync

# Install with dev dependencies
uv sync --extra dev

# Run tests
uv run pytest

# Format code
uv run ruff format src/
uv run ruff check src/ --fix

License

MIT

Credits

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

nanobanana_py-0.2.0.tar.gz (135.2 kB view details)

Uploaded Source

Built Distribution

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

nanobanana_py-0.2.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file nanobanana_py-0.2.0.tar.gz.

File metadata

  • Download URL: nanobanana_py-0.2.0.tar.gz
  • Upload date:
  • Size: 135.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanobanana_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7cef16c1df1a5a0fbad29b06a3a0df95c1975412e8dbd922e7f6b3fc89c5e611
MD5 3491ec674b5f2c0f9ce42cd72935aecc
BLAKE2b-256 c979613fe60bb0b8f754cba913c4f9fc354d2bf87ffa3757bd793cf53e615701

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanobanana_py-0.2.0.tar.gz:

Publisher: publish.yml on yazelin/nanobanana-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nanobanana_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: nanobanana_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nanobanana_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec9769bd41b30e6f367c8296042e4005397d3b00ed07c82f3205a5628e2c0ccc
MD5 7426badd32ca320d408b2c33c21dc05a
BLAKE2b-256 c202952022e4c9e6d629795addff2a45738c338a0938eadf39b1b53c4515c1e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for nanobanana_py-0.2.0-py3-none-any.whl:

Publisher: publish.yml on yazelin/nanobanana-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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