Skip to main content

Imagenation 🎨

PyPI version Python 3.7+ License: BSD-3-Clause

Generate AI Images in Batches with Google's Imagen. Transform text prompts and optional image inputs into stunning visuals, effortlessly.

Banner

Features

  • Text-to-Image: Generate images from text descriptions
  • Text+Image-to-Image: Modify existing images with text prompts
  • CLI Interface: Direct command-line usage
  • Batch Processing: Process multiple images from CSV/JSON files
  • Library Support: Import and use in your Python projects
  • Rate Limiting: Built-in rate limiting with configurable delays to prevent API quota issues

Quick Start

  1. Install dependencies:

    pip install -r requirements.txt
    
  2. Set up API key in .env:

    GOOGLE_API_KEY=your_api_key_here
    
  3. Generate an image:

    ./start.sh -it "A beautiful sunset over mountains" -o sunset.png
    

Usage

Command Line

# Text to image (with default rate limiting)
./start.sh -it "A majestic dragon in a fantasy landscape" -o dragon.png

# Text + image to image  
./start.sh -it "Add a rainbow to this landscape" -ii photo.jpg -o rainbow_photo.png

# Batch processing from CSV
./start.sh --csv batch_data.csv

# Batch processing from JSON
./start.sh --json batch_data.json

# Custom rate limiting for paid tier (faster processing)
./start.sh -it "Beautiful landscape" -o output.png --delay 0.2

# Conservative rate limiting for batch processing
./start.sh --csv large_batch.csv --delay 15.0

Rate Limiting

The tool includes built-in rate limiting to prevent hitting Google API quotas:

  • Default delay: 12 seconds between requests (5 requests/minute for free tier)
  • Custom delay: Use --delay parameter to adjust timing
  • Automatic handling: Built-in wait times and error handling for rate limit errors

Rate Limiting Recommendations

Tier Delay Requests/Minute Use Case
Free 12s (default) 5 Personal use, occasional generation
Paid 0.2s 300 High-volume processing, development
Batch 15s+ 4 Large batch processing, quota conservation

Rate Limiting Examples

# Free tier (default 12s delay)
./start.sh -it "sunset" -o output.png

# Paid tier (faster processing)
./start.sh -it "sunset" -o output.png --delay 0.2

# Batch processing with conservative delay
./start.sh --csv batch.csv --delay 15.0

# Library usage with custom rate limiting
from imagenation import ImagenationGenerator
gen = ImagenationGenerator(rate_limit_delay=0.2)  # 300 RPM

Python Library

from imagenation import ImagenationGenerator

# Initialize generator with custom rate limiting
gen = ImagenationGenerator(rate_limit_delay=0.2)  # 300 RPM for paid tier

# Generate text-to-image
gen.generate_text_to_image("A serene lake at sunset", "lake.png")

# Generate text+image-to-image
gen.generate_text_image_to_image(
    "Make this photo look vintage", 
    "input.jpg", 
    "vintage_output.jpg"
)

Alternative Usage

# Using Python module directly
python -m imagenation -it "Beautiful landscape" -o output.png

# Using original script (backward compatibility)
python imagenation.py -it "Beautiful landscape" -o output.png

File Formats

CSV Format

input_text,input_image_path,output_image_name
"A beautiful sunset","","sunset.png"
"Add a rainbow","landscape.jpg","rainbow_landscape.png"

JSON Format

[
  {
    "input_text": "A beautiful sunset",
    "input_image_path": "",
    "output_image_name": "sunset.png"
  },
  {
    "input_text": "Add a rainbow", 
    "input_image_path": "landscape.jpg",
    "output_image_name": "rainbow_landscape.png"
  }
]

Requirements

  • Python 3.7+
  • Google API key with Gemini access
  • Dependencies: google-genai, pillow, python-dotenv

Project Structure

imagenation/
├── imagenation/           # Main package
│   ├── __init__.py       # Package exports
│   ├── generator.py      # Core generation logic with rate limiting
│   ├── cli.py           # Command-line interface
│   └── __main__.py      # Module entry point
├── imagenation.py        # Backward compatibility script
├── start.sh             # Setup and run script
├── requirements.txt     # Dependencies
├── .env                # API key configuration
└── README.md           # This file

Rate Limiting Details

The tool automatically handles rate limiting to prevent API quota issues:

  • Built-in delays: Automatic wait times between requests
  • Error handling: Graceful handling of 429 rate limit errors
  • Configurable: Adjust timing via --delay parameter or constructor
  • Batch processing: Essential for processing large numbers of images without hitting daily limits

When rate limits are exceeded, the tool provides clear feedback and suggestions for adjusting the delay parameter.


🌊 Made with Good Vibes by Pedro, Claude, and Gemini 🌊

Release files for imagenation 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imagenation 1.0.1
File Size Uploaded
imagenation-1.0.1.tar.gz 1.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for imagenation 1.0.1
File Interpreter ABI Platform
imagenation-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 1.3 MB

Release files / imagenation-1.0.1.tar.gz

Download URL imagenation-1.0.1.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
9bbb738c61621c42d5e4fbf5b1817b1b287e9c4a31051817a79217f0fb7d6b61
BLAKE2b-256 checksum
How to use checksums
7c57ab371ba58fa9846e92e0de443bef51cc142769573e21d868e7f4c1266ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / imagenation-1.0.1-py3-none-any.whl

Download URL imagenation-1.0.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
723df87947b92eed1146fa49c48b2390ac36ad133f3e69e4762178c87ba9bd91
BLAKE2b-256 checksum
How to use checksums
7ace9d2ce27c7543196787e8835d49266c04617a6ad140640171ab85e4c7079c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page