DEV Community

Cover image for Build an Auto-Posting Instagram Bot in 20 Lines of Python
Mikhail Bogovalov
Mikhail Bogovalov

Posted on

Build an Auto-Posting Instagram Bot in 20 Lines of Python

What if your AI agent could generate professional Instagram posts and schedule them automatically — with zero design skills?

I built RendrKit, a Design API that turns text into production-ready graphics. Today I'll show you how to combine it with Python to create an auto-posting Instagram bot in ~20 lines of code.

What We're Building

A Python script that:

  1. Takes a topic (e.g., "productivity tips")
  2. Generates a professional Instagram graphic via API
  3. Posts it to Instagram automatically
  4. Runs on a schedule (daily, hourly, whatever)

Here's the end result — generated entirely from text:

Example output

Prerequisites

pip install rendrkit instagrapi requests
Enter fullscreen mode Exit fullscreen mode

The Code (Yes, It's Actually 20 Lines)

from rendrkit import RendrKit
from instagrapi import Client
from datetime import datetime

# Setup
rk = RendrKit(api_key="your-rendrkit-key")
ig = Client()
ig.login("your_instagram", "your_password")

# Generate image from a text prompt
result = rk.generate(
    prompt="A motivational quote about productivity: 'Ship fast, learn faster.' Modern dark gradient design with bold typography",
    size="1080x1080"
)

# Download the image
import requests
image_path = "/tmp/post.png"
with open(image_path, "wb") as f:
    f.write(requests.get(result["url"]).content)

# Post to Instagram
ig.photo_upload(image_path, "Ship fast, learn faster 🚀\n\n#productivity #startup #buildinpublic")
print(f"Posted at {datetime.now()}")
Enter fullscreen mode Exit fullscreen mode

That's it. Run it, and you've got a fresh Instagram post generated from nothing but text.

Level Up: Use Templates for Consistent Branding

The prompt mode is great for one-offs, but for a branded feed you want consistency. RendrKit has 69+ templates — pick one and fill in the slots:

result = rk.generate(
    template_id="social-quote",
    slots={
        "heading": "Ship fast, learn faster.",
        "subheading": "The best feedback comes from real users.",
        "accent_color": "#6366F1"
    },
    size="1080x1080"
)
Enter fullscreen mode Exit fullscreen mode

Same API, but now every post matches your brand colors and layout. No more random AI-generated chaos.

Make It Automatic: Run Daily with Schedule

import schedule
import time
import random

tips = [
    {"heading": "Ship fast, learn faster.", "subheading": "Real users give the best feedback."},
    {"heading": "Done > Perfect", "subheading": "Perfection is the enemy of progress."},
    {"heading": "Build in public.", "subheading": "Your journey inspires others."},
    {"heading": "Solve your own problem.", "subheading": "The best startups come from personal pain."},
    {"heading": "Talk to users daily.", "subheading": "Metrics lie. Conversations don't."},
]

def post_daily():
    tip = random.choice(tips)
    result = rk.generate(
        template_id="social-quote",
        slots={**tip, "accent_color": "#6366F1"},
        size="1080x1080"
    )
    with open("/tmp/post.png", "wb") as f:
        f.write(requests.get(result["url"]).content)
    ig.photo_upload("/tmp/post.png", f"{tip['heading']}\n\n#startup #buildinpublic #productivity")
    print(f"Posted: {tip['heading']}")

schedule.every().day.at("09:00").do(post_daily)

while True:
    schedule.run_pending()
    time.sleep(60)
Enter fullscreen mode Exit fullscreen mode

Set it and forget it. Your Instagram posts itself every morning at 9 AM.

Why Not Just Use DALL-E or Midjourney?

Good question. I tried that first. Here's why templates win for social media:

DALL-E / Midjourney RendrKit Templates
Consistency Every image looks different Same brand, every time
Text rendering Misspells words constantly Pixel-perfect typography
Speed 5-15 seconds 1-2 seconds
Cost $0.04-0.08/image $0.001/image (direct render)
Brand control Hope for the best Exact colors, fonts, layout

For generative art? Use DALL-E. For professional branded content? Use templates.

Other Ideas You Can Build

This same pattern works for:

  • Twitter/X auto-poster — generate OG images for your threads
  • Email newsletter headers — fresh header image every issue
  • Slack bot/motivate command that generates and posts a quote
  • E-commerce — auto-generate product banners from your catalog
  • Certificates — generate completion certificates for your course platform

Available Templates

RendrKit has 69+ templates including:

  • social-quote — motivational quotes, tips
  • blog-post-cover — article headers
  • product-showcase — product announcements
  • stats-banner — metrics and numbers
  • hiring-post — job announcements
  • event-poster — event promotions
  • certificate — completion certificates
  • invoice — business documents

Full list: rendrkit.dev/templates

Get Started

  1. Grab a free API key at rendrkit.dev
  2. pip install rendrkit
  3. Start generating

The free tier gives you 50 images/month — enough to post daily and test everything.


I'm building RendrKit as a solo dev. If you have questions or feature requests, hit me up on Twitter/X or drop a comment below.

Top comments (0)