A production-ready FastAPI backend for social media scraping using Apify, Celery, and Supabase. Includes a minimal Bootstrap UI for submitting scrape jobs, viewing statuses, and displaying results.
- FastAPI backend (async, modern, easy to extend)
- Celery + Redis for background job processing
- Supabase for storing job metadata and results
- Minimal Bootstrap UI (no JS required)
- .env for secrets (see
.env.example) - SQLite fallback for local dev (if you don't want to use Supabase)
app/
main.py # FastAPI app, routes, web UI
celery_app.py # Celery config
tasks.py # Celery background tasks
apify_utils.py # Apify integration helpers
supabase_utils.py # Supabase integration helpers
models.py # Pydantic models & DB schema helpers
config.py # Env loading, settings
templates/
base.html
index.html # Form to submit scrape jobs
jobs.html # List job statuses
results.html # Show scraped results
static/
(Bootstrap CSS, logo, etc.)
tasks/
worker.py # Celery worker runner
.env.example # Example env vars
requirements.txt # All dependencies
run.py # Local dev launcher
README.md # This file
- Clone the repo
- Install dependencies
pip install -r requirements.txt
- Copy and edit your .env
cp .env.example .env # Fill in your APIFY_TOKEN, SUPABASE_URL, SUPABASE_KEY, etc. - Create Supabase tables (see schema below)
- Start Redis (for Celery)
# On Windows: use Docker Desktop or install Redis from https://github.com/microsoftarchive/redis/releases redis-server - Start Celery worker
celery -A app.tasks.celery worker --loglevel=info
- Run the app
python run.py # Visit http://localhost:8000
You need two tables:
| Column | Type | Notes |
|---|---|---|
| id | uuid (PK) | auto-generated |
| platform | text | e.g. 'instagram', 'twitter' |
| keyword | text | URL or keyword |
| frequency | text | e.g. 'daily', 'once' |
| run_id | text | Apify run ID |
| status | text | pending/running/complete |
| created_at | timestamptz | default now() |
| updated_at | timestamptz |
| Column | Type | Notes |
|---|---|---|
| id | uuid (PK) | auto-generated |
| job_id | uuid (FK) | references scrape_jobs(id) |
| data | jsonb | scraped & processed data |
| created_at | timestamptz | default now() |
- Upload your code to PythonAnywhere.
- Create a virtualenv and install requirements:
mkvirtualenv myenv --python=python3.10 pip install -r requirements.txt
- Set up your
.envin your home directory. - Enable ASGI support (request if not enabled).
- Use this command to run FastAPI:
/home/YOURUSERNAME/.virtualenvs/myenv/bin/uvicorn --app-dir /home/YOURUSERNAME/Apify_Scrape_social/app --uds ${DOMAIN_SOCKET} main:app - Set up a Redis instance (use a free cloud Redis if needed, or run locally for dev).
- Start Celery worker in a console:
celery -A app.tasks.celery worker --loglevel=info
- Visit your PythonAnywhere subdomain.
- Create a VM (Ubuntu recommended).
- Install Python 3.10+, Redis, and git.
- Clone your repo and set up a virtualenv.
- Install requirements and set up
.env. - Use systemd or Docker to run Uvicorn and Celery (see CodeArmo FastAPI deploy guide).
- Set up Nginx as a reverse proxy for production.
- Go to
/to submit a new scrape job. /jobsto see job statuses./results/{job_id}to see results.
MIT