Jump to content

The 7-Line Python Script That Accidentally Became My First AI SaaS

From JOHNWICK

Photo by Fotis Fotopoulos on Unsplash

1. When I Realized AI Didn’t Just Have to Be “Fun” I used to build small AI scripts just for practice — summaries, chatbots, keyword extractors, all the typical experimentation.

One night, while manually summarizing long reports for a client, something clicked:

What if this tool ran automatically? What if multiple clients used it at the same time? What if they paid monthly?

That thought turned into a 7-line prototype that now earns recurring income while I sleep.

2. The Business Model Was Surprisingly Simple The workflow looked like this:

Client uploads a file (text, PDF, CSV) Python summarizes or analyzes it Results come back instantly via API Usage is logged for billing

No complex UI, no dashboards, no ML models to train. Just clean automation that delivered real value.

3. The Lean Tech Stack I kept the entire system incredibly lightweight. FastAPI handled the backend and exposed the AI as a web service, while OpenAI powered the summarization and intelligence layer. For tracking usage, I used a simple SQLite database, and Stripe managed recurring subscription payments without any manual invoicing. Everything was deployed on a minimal $5 Render server, which turned out to be more than enough to run the whole system smoothly. In total, launching the first working version cost me just five dollars and one weekend of focused building.

4. The 7-Line MVP That Started It All This was the entire product at first:

from fastapi import FastAPI, File, UploadFile
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY")
app = FastAPI()

@app.post("/summarize")
async def summarize(file: UploadFile = File(...)):
    text = (await file.read()).decode()
    res = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role":"user","content":f"Summarize:\n{text}"}])
    return {"summary": res.choices[0].message.content}

Run with:

uvicorn main:app --reload

Upload a file → Receive a summary in seconds.
That was enough to show potential clients.

5. A Zero-JavaScript Frontend To make it simple for non-technical users, I wrapped the API in Streamlit:

import streamlit as st
import requests

st.title("AI Summary Generator")
file = st.file_uploader("Upload your text file")

if file:
    res = requests.post("http://localhost:8000/summarize", files={"file": file})
    st.write(res.json()["summary"])

Instant web interface. No React, no CSS headaches.

6. Logging Usage for Billing

import sqlite3
from datetime import datetime

def log_request(client_email, tokens_used):
    conn = sqlite3.connect("usage.db")
    conn.execute("""CREATE TABLE IF NOT EXISTS logs
                    (email TEXT, tokens INT, date TEXT)""")
    conn.execute("INSERT INTO logs VALUES (?, ?, ?)",
                 (client_email, tokens_used, datetime.now().isoformat()))
    conn.commit()
    conn.close()

Usage analytics = automated invoices.

7. Turning It into Real Money Using Stripe

import stripe
stripe.api_key = "YOUR_STRIPE_SECRET"

@app.post("/create-checkout")
async def checkout(email: str):
    session = stripe.checkout.Session.create(
        payment_method_types=["card"],
        line_items=[{"price_data": {"currency":"usd","unit_amount":2000,
        "product_data":{"name":"AI Summary Subscription"}}, "quantity":1}],
        mode="subscription",
        success_url="https://yourapp.com/success",
        cancel_url="https://yourapp.com/cancel",
        customer_email=email)
    return {"checkout_url": session.url}

Clients pay → access unlocks → recurring revenue.

8. Expanding Services Was Easy

@app.post("/extract_keywords")
async def extract(file: UploadFile = File(...)):
    text = (await file.read()).decode()
    res = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role":"user","content":f"Extract keywords:\n{text}"}])
    return {"keywords": res.choices[0].message.content.split(", ")}

Now I offer:

  • Summaries
  • Keyword extraction
  • SEO titles
  • Sentiment analysis
  • Daily automated reports

9. Deployment Render + Procfile:

web: uvicorn main:app --host 0.0.0.0 --port 10000

Push to GitHub → auto-deploy.
Done.

10. Pricing Stripe handles payments.
Python handles automation.
I handle nothing.

11. What Started as 7 Lines Is Now a Micro-SaaS Today the system: Runs without supervision
Bills automatically
Logs requests and usage
Sends scheduled analytical reports
Generates recurring monthly revenue And it all began with one simple thought: People don’t want AI models — they want automated results. If you’re a Python developer, you’re closer to a business than you think. Build the simplest version possible — then iterate.

Read the full article here: https://ai.plainenglish.io/the-7-line-python-script-that-accidentally-became-my-first-ai-saas-c126fc4d7965