Skip to main content

A powerful Python library and REST API for creating Ghost CMS blog posts with AI-powered features including Flask API and Docker deployment

Project description

Ghost Blog Smart

๐Ÿš€ A comprehensive solution for Ghost CMS blog management with AI-powered features

Available as both a Python Package and REST API with multiple deployment options including Docker, local installation, and PyPI package.

PyPI version Docker Hub GitHub Actions License: MIT Python 3.9+

๐ŸŽฏ Choose Your Setup Method

Method Best For Example Files Documentation Section
๐Ÿณ Docker API Production deployment, quick testing example_usage_API.js Docker Deployment
๐Ÿ Python Package Python developers, scripting example_usage.py Python Package
๐ŸŒ Local API Development, customization example_usage_API.js Local API Setup
๐Ÿ“ฆ PyPI Install Simple Python integration example_usage.py PyPI Installation

๐Ÿ“– Table of Contents

๐Ÿš€ Getting Started

๐Ÿ“š Usage Examples

๐Ÿ“– Documentation


๐Ÿณ Docker Deployment

Recommended for: Production environments, quick testing, isolation

Example File: example_usage_API.js (Node.js client for REST API)

Quick Start

# Pull and run the pre-built Docker image
docker pull betashow/ghost-blog-smart-api:latest

# Run with your credentials
docker run -d \
  -p 5000:5000 \
  -e GHOST_ADMIN_API_KEY="your_key_id:your_secret_key" \
  -e GHOST_API_URL="https://your-ghost-site.com" \
  -e GEMINI_API_KEY="your_gemini_key" \
  -e REPLICATE_API_TOKEN="r8_your_replicate_token" \
  -e FLASK_API_KEY="your_secure_api_key" \
  --name ghost-blog-api \
  betashow/ghost-blog-smart-api:latest

# Test the API
curl http://localhost:5000/health

Docker Compose

version: '3.8'
services:
  ghost-blog-smart-api:
    image: betashow/ghost-blog-smart-api:latest
    ports:
      - "5000:5000"
    environment:
      - GHOST_ADMIN_API_KEY=your_key_id:your_secret_key
      - GHOST_API_URL=https://your-ghost-site.com
      - GEMINI_API_KEY=your_gemini_key
      - REPLICATE_API_TOKEN=r8_your_replicate_token
      - FLASK_API_KEY=your_secure_api_key

Next Steps:


๐Ÿ Python Package Usage

Recommended for: Python developers, scripting, direct integration

Example File: example_usage.py (Pure Python usage)

Installation

pip install ghost-blog-smart

Basic Usage

from ghost_blog_smart import smart_blog_gateway

# Smart Gateway Method (Recommended)
result = smart_blog_gateway(
    "AI healthcare benefits: faster diagnosis, better accuracy, cost reduction",
    status="published"
)

if result['success']:
    print(f"Post created: {result['url']}")

Next Steps:


๐Ÿ“ฆ PyPI Installation

Recommended for: Simple Python projects, minimal setup

# Install from PyPI
pip install ghost-blog-smart

# Use directly in your Python code
from ghost_blog_smart import create_ghost_blog_post, smart_blog_gateway

Create .env file with your credentials:

GHOST_ADMIN_API_KEY=your_admin_api_key_id:your_secret_key_here
GHOST_API_URL=https://your-ghost-site.com
GEMINI_API_KEY=your_gemini_api_key_here
REPLICATE_API_TOKEN=r8_your_replicate_api_token_here

๐ŸŒ Local API Development

Recommended for: Development, customization, testing

Example Files: example_usage_API.js (Node.js client) + Local Flask API

Setup

# Clone the repository
git clone https://github.com/preangelleo/ghost_blog_smart.git
cd ghost_blog_smart

# Install dependencies
pip install -r requirements.txt
pip install -r requirements-api.txt
pip install -e .

# Set up environment variables
cp .env.example .env
# Edit .env with your credentials

# Run the Flask API
python app.py

API runs on: http://localhost:5000

Next Steps:


๐Ÿ’ป Python Examples (example_usage.py)

For: Python Package usage, PyPI installation, direct Python integration

Key Examples from example_usage.py:

Smart Gateway (AI-Enhanced Creation)

from ghost_blog_smart import smart_blog_gateway

result = smart_blog_gateway(
    "Write about AI benefits in healthcare: faster diagnosis, better accuracy",
    status="published",
    preferred_language="English"
)

Traditional Method

from ghost_blog_smart import create_ghost_blog_post

result = create_ghost_blog_post(
    title="My Blog Post",
    content="Post content in **Markdown**",
    excerpt="Brief summary",
    tags=["Tutorial", "AI"],
    status="published",
    use_generated_feature_image=True,
    prefer_flux=True
)

Blog Management

from ghost_blog_smart import get_ghost_posts, update_ghost_post, delete_ghost_post

# Get posts
posts = get_ghost_posts(limit=5, status='published')

# Update post
update_ghost_post(post_id="abc123", featured=True)

# Delete post
delete_ghost_post(post_id="abc123")

๐Ÿ“ Complete examples available in: example_usage.py


๐ŸŒ Node.js API Examples (example_usage_API.js)

For: Docker deployment, local API server, REST API integration

Prerequisites

npm install axios  # HTTP client for API calls

Key Examples from example_usage_API.js:

Configuration

const CONFIG = {
    baseUrl: 'http://localhost:5000',
    apiKey: 'your_secure_api_key',
    timeout: 300000, // 5 minutes for image generation
    imageTimeout: 300000, // Extended timeout for image endpoints
    standardTimeout: 30000, // Standard timeout for other endpoints
};

Create Blog Post via API

const postData = {
    title: "My API Blog Post",
    content: "Post content in **Markdown**",
    excerpt: "Brief summary",
    tags: ["API", "Node.js"],
    status: "published",
    use_generated_feature_image: true,
    prefer_flux: true,
    image_aspect_ratio: "16:9"
};

const response = await api.post('/api/posts', postData);

Smart Create via API

const smartData = {
    user_input: "Write about JavaScript testing frameworks: Jest vs Mocha vs Cypress",
    status: "draft",
    preferred_language: "English"
};

const response = await api.post('/api/smart-create', smartData);

Running Tests

# Run all endpoint tests
node example_usage_API.js

# Run specific test
node example_usage_API.js health

# Run with custom timeout (5 minutes for image generation)
node example_usage_API.js --timeout 300000

# Production mode (creates real posts)
node example_usage_API.js --production

๐Ÿ“ Complete examples available in: example_usage_API.js


โœจ Features

๐Ÿค– Smart AI Gateway

  • Intelligent Routing - Automatically determines if content needs rewriting
  • Structured Output - Uses Gemini's structured output for consistent formatting
  • Function Calling - Leverages Gemini function calling for smart decision making
  • Auto Enhancement - Transforms scattered ideas into complete blog posts
  • Missing Component Detection - Automatically generates titles, excerpts, and tags

๐ŸŽจ Dual AI Image Generation

  • ๐Ÿ”ฅ Replicate Flux-dev: Ultra-fast generation (3-7 seconds), photorealistic images, WebP format
  • ๐Ÿ”๏ธ Google Imagen-4: Professional quality, advanced prompt understanding, PNG format
  • Automatic Fallback System: Intelligent provider switching for maximum reliability
  • Provider Selection: Choose your preferred provider or let the system decide
  • Multiple Aspect Ratios: 16:9, 1:1, 9:16, 4:3, 3:2 support

๐Ÿ“ Content Management

  • Smart Content Formatting - Auto-format plain text to beautiful Markdown with Gemini AI
  • YouTube-Style Slugs - Generate 11-character slugs like YouTube video IDs
  • Multi-language Support - Chinese to Pinyin conversion for slugs
  • Language Translation - Auto-translate content to any target language
  • Flexible Image Handling - Support for URLs, local files, base64 data

๐Ÿ“Š Blog Management

  • Advanced Listing - Get posts with powerful filtering options
  • Search & Query - Full-text search across all posts
  • Date Range Filtering - Find posts by publication/creation date
  • Update & Delete - Modify or remove posts with comprehensive options
  • Batch Operations - Process multiple posts efficiently
  • Detailed Analytics - Get complete post details and summaries

๐Ÿ”ง REST API Reference

Base URL Structure

http://localhost:5000/          # API information
http://localhost:5000/health    # Health check
http://localhost:5000/api/      # All blog endpoints

Authentication

All API endpoints (except / and /health) require authentication:

curl -H "X-API-Key: your_api_key" http://localhost:5000/api/posts

Standard Response Format

{
  "success": true,
  "timestamp": "2024-01-01T00:00:00.000000Z",
  "data": {
    // Response data here
  }
}

โš ๏ธ TIMEOUT CONFIGURATION NOTICE

  • Image Generation Endpoints: /api/posts (with use_generated_feature_image: true) and /api/posts/{id}/image require extended timeouts
  • Recommended Client Timeout: 5 minutes (300 seconds) minimum
  • Typical Response Times: 60-300 seconds for image generation
  • Without Images: Standard 30-second timeout is sufficient

๐Ÿ“ Core Endpoints

Create Blog Post โš ๏ธ Extended Timeout for Images

POST /api/posts
Content-Type: application/json
X-API-Key: your_api_key

{
  "title": "My Blog Post",
  "content": "Post content in **Markdown**",
  "excerpt": "Brief summary",
  "tags": ["Tag1", "Tag2"],
  "status": "published",
  "use_generated_feature_image": true,
  "prefer_flux": true,
  "image_aspect_ratio": "16:9"
}

โฑ๏ธ Important: When use_generated_feature_image: true is used, generation can take 60-300 seconds. Set client timeout to at least 5 minutes (300 seconds).

Smart Create (AI-Enhanced)

POST /api/smart-create
Content-Type: application/json
X-API-Key: your_api_key

{
  "user_input": "Write about AI benefits in healthcare",
  "status": "draft",
  "preferred_language": "English"
}

Get Posts

GET /api/posts?limit=5&status=published&featured=true
X-API-Key: your_api_key

Update Post Image โš ๏ธ High Timeout Required

PUT /api/posts/{post_id}/image
Content-Type: application/json
X-API-Key: your_api_key

{
  "use_generated_feature_image": true,
  "prefer_imagen": true,
  "image_aspect_ratio": "16:9"
}

โฑ๏ธ Important: Image generation endpoints can take 60-300 seconds to complete. Set client timeout to at least 5 minutes (300 seconds) for reliable operation.

๐Ÿ“‹ Complete Endpoint List

Endpoint Method Description Auth Required Timeout
/ GET API information โŒ Standard
/health GET Health check โŒ Standard
/api/posts POST Create blog post โœ… Extended*
/api/smart-create POST AI-enhanced creation โœ… Standard
/api/posts GET List posts โœ… Standard
/api/posts/advanced GET Advanced search โœ… Standard
/api/posts/{id} GET Get post details โœ… Standard
/api/posts/{id} PUT/PATCH Update post โœ… Standard
/api/posts/{id} DELETE Delete post โœ… Standard
/api/posts/{id}/image PUT Update post image โœ… Extended*
/api/posts/summary GET Posts summary โœ… Standard
/api/posts/batch-details POST Batch get details โœ… Standard
/api/posts/search/by-date-pattern GET Date search โœ… Standard

*Extended = 5 minutes (300 seconds) for image generation


โฑ๏ธ Performance & Timeout Guidelines

Image Generation Performance

  • Replicate Flux: 3-7 seconds (ultra-fast)
  • Google Imagen: 10-15 seconds (professional quality)
  • Upload & Processing: Additional 45-60 seconds
  • Total Time: 60-300 seconds for complete image generation

Recommended Client Timeouts

// For endpoints WITH image generation
const imageApiTimeout = 300000; // 5 minutes

// For endpoints WITHOUT image generation  
const standardTimeout = 30000; // 30 seconds

Production Testing Results

โœ… All endpoints functional
โš ๏ธ Image generation requires extended timeout
๐Ÿ’ก Recommendation: Always set 5-minute timeout for image endpoints


๐Ÿงช Testing

Python Package Testing

# Set test mode to avoid actual posting
python example_usage.py  # Uses is_test=True by default

API Testing (Docker/Local)

# Comprehensive test suite
node example_usage_API.js

# Individual endpoint tests
node example_usage_API.js health
node example_usage_API.js create
node example_usage_API.js smart

# Production mode (creates real posts)
node example_usage_API.js --production

# Extended timeout for image generation
node example_usage_API.js --timeout 300000

Docker Testing Guide

See TESTING_GUIDE.md for comprehensive Docker testing instructions.


๐Ÿ“ Project Structure

ghost-blog-smart/
โ”œโ”€โ”€ ghost_blog_smart/             # Main Python package
โ”‚   โ”œโ”€โ”€ __init__.py              # Package exports
โ”‚   โ”œโ”€โ”€ main_functions.py        # Core API functions
โ”‚   โ”œโ”€โ”€ smart_gateway.py         # AI-powered routing
โ”‚   โ”œโ”€โ”€ post_management.py       # Advanced management
โ”‚   โ””โ”€โ”€ *.py                    # Other modules
โ”œโ”€โ”€ example_usage.py             # ๐Ÿ Python package examples
โ”œโ”€โ”€ example_usage_API.js         # ๐ŸŒ Node.js API client examples  
โ”œโ”€โ”€ app.py                       # ๐Ÿš€ Flask REST API server
โ”œโ”€โ”€ Dockerfile                   # ๐Ÿณ Docker configuration
โ”œโ”€โ”€ docker-compose.yml          # ๐Ÿณ Docker Compose setup
โ”œโ”€โ”€ requirements.txt             # Python dependencies
โ”œโ”€โ”€ setup.py                    # PyPI package setup
โ”œโ”€โ”€ TESTING_GUIDE.md            # ๐Ÿงช Docker testing instructions
โ””โ”€โ”€ README.md                   # ๐Ÿ“– This documentation

๐ŸŽจ Image Generation Comparison

Feature Replicate Flux-dev Google Imagen-4
Speed โšก Ultra-fast (3-7s) ๐Ÿข Moderate (10-15s)
Quality ๐Ÿ”ฅ Photorealistic ๐Ÿ”๏ธ Professional
Format ๐Ÿ“ WebP (smaller) ๐Ÿ“ PNG (lossless)
Cost ๐Ÿ’ฐ Pay-per-use ๐Ÿ’ฐ API quota based
Best For Realistic scenes, portraits Abstract concepts, artistic

Supported Aspect Ratios:

  • 16:9 - Widescreen (1920x1080) - Default
  • 1:1 - Square (1024x1024) - Great for social media
  • 9:16 - Portrait (1080x1920) - Mobile-optimized
  • 4:3 - Traditional (1024x768) - Classic photo ratio
  • 3:2 - DSLR (1536x1024) - Professional photography

๐Ÿ“‹ Prerequisites

  • Python 3.8+
  • Ghost CMS instance with Admin API access
  • Image Generation (choose one or both):
    • Google Gemini API key (for Imagen-4 generation)
    • Replicate API token (for Flux-dev generation)

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


๐Ÿ“„ License

MIT License - see LICENSE file for details


๐Ÿ™ Acknowledgments

  • Ghost CMS for the excellent blogging platform
  • Google Gemini & Imagen for AI capabilities
  • Replicate for ultra-fast Flux generation
  • The open-source community

๐Ÿ“ž Support

For issues or questions, please open an issue on GitHub.


Made with โค๏ธ for the Ghost CMS community

โœจ Available as both Python Package and REST API with comprehensive Docker support!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

ghost_blog_smart-1.1.3-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

File details

Details for the file ghost_blog_smart-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for ghost_blog_smart-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 95affe8c99749b07745e377a3f3a4ba51b0ecf9ea04a0a40abd001b87a084f65
MD5 90855ba4e2644ba6ee4f79d1b5e5bee4
BLAKE2b-256 e633efc7f8f00cc1fa976d13a9b2538ea73b93308f3327467c0fc49b574886e3

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