A single-page, personal-use follower counter for Instagram. Enter a username, watch the follower count update live in big centered numbers, auto-refreshing every 2 minutes — built to look like the "YouTube live subscriber count" trackers, but for Instagram.
- Enter any public Instagram username and track its live follower count
- Avatar, full name, verified badge, and handle pulled from the same single profile request used for the follower count — no extra API calls
- Auto-refreshes every 120 seconds with a visible countdown
- Odometer-style roll animation — only the digits that actually changed animate, shared leading digits stay static
- Loading screen (spinner) while a lookup is in flight, replacing the search box entirely
- Deep-linkable via
?user=<username>, remembers your last search insessionStoragefor the current browser tab - Light theme, responsive layout
- In-memory caching (2 min TTL) so repeated requests don't hammer Instagram
- This uses your own Instagram account's credentials to look up follower counts via Instaloader. Instagram's Terms of Service prohibit automated access — this is built for personal, light-touch use, not as a public-facing product or a tool for scraping at any volume.
- The server never logs in by itself. It only ever loads a session file you generate locally and copy over. Logging in fresh from a server's IP is the fastest way to trigger a 2FA/checkpoint challenge that a headless process can't answer.
- Querying many different profiles back-to-back from one account is the fastest way to get rate-limited or checkpointed by Instagram. Keep usage light — this is a single-user tool, not a multi-tenant service.
- There is no way to get real-time follower counts for accounts you don't control via any official, free API — Instagram's Graph API only exposes data for Business/Creator accounts that have explicitly authorized your app. This project works the same way the unofficial "live counter" novelty sites do: by reading the same public profile data Instagram's own website loads, via a logged-in session.
Browser ──fetch──▶ Flask (app.py) ──Instaloader──▶ Instagram
│
└─ in-memory cache (2 min TTL)
GET /api/followers/<username>returns{ username, full_name, is_verified, followers, updated_at, cached }— all pulled from one Instaloader profile request, cached for 2 minutes.GET /api/avatar/<username>proxies the profile photo through the server. Instagram's CDN blocks browsers from hotlinking the image directly (Referer-based protection), and the raw CDN URL is a signed, expiring token anyway — so the server fetches the bytes itself and serves them from its own domain, cached for an hour client-side.GET /health→{ "status": "ok" }, for uptime checks.
git clone https://github.com/Avdhesh-Varshney/instagram-live-follower-counter.git
cd instagram-live-follower-counter
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# edit .env and set INSTAGRAM_USERNAME to your own Instagram usernameTo close the virtual environment later, run deactivate in the same
terminal.
python generate_session.pyThis prompts for your Instagram username/password, logs in once, walks you
through a 2FA prompt interactively if Instagram asks for one, and writes
sessions/instagram.session. Your password is never stored — only the
resulting session file, which app.py loads on startup.
python app.pyBy default it listens on port 5000. On macOS, port 5000 is often taken by AirPlay Receiver — if you hit "Address already in use", run instead:
PORT=5050 python app.pyVisit http://localhost:5000 (or :5050). Try
http://localhost:5000/?user=instagram to deep-link directly to a username.
If you ever regenerate the session or change
.env, restartapp.py— it only reads the session and env vars once, at startup.
| Endpoint | Method | Response |
|---|---|---|
/api/followers/<username> |
GET | { username, full_name, is_verified, profile_pic_url, followers, updated_at, cached } or { error } |
/api/avatar/<username> |
GET | Image bytes (proxied profile photo) |
/health |
GET | { "status": "ok" } |
Render's free tier has no persistent disk and no Shell tab — and free services spin down after ~15 minutes of inactivity, wiping the filesystem on every spin-up. That rules out copying the session file onto disk. Use Option A below for free tier; Option B is for a paid instance type if you'd rather use a disk.
Free-tier services also cold-start (~30–60s) on the first request after being asleep. In practice this app's own 120s polling tends to keep it warm while a browser tab has it open, but the very first visit after a period of nobody using it will be slow to respond.
-
New → Web Service → connect this repo.
-
Runtime: Python 3. Build command:
pip install -r requirements.txt. Start command:gunicorn app:app --workers 1 --threads 4 --timeout 60 --bind 0.0.0.0:$PORT. -
Locally, run
base64 -i sessions/instagram.sessionand copy the printed line (session files are tiny, always a single line). -
Set
INSTAGRAM_USERNAMEandCACHE_TTL_SECONDS=120as regular Environment Variables. Provide the base64 string from step 3 via either:- an Environment Variable named
INSTAGRAM_SESSION_B64, or - a Secret File (Render's Environment tab → Secret Files) named
exactly
INSTAGRAM_SESSION_B64, pasting the base64 string as its contents. This is Render's purpose-built feature for exactly this kind of secret, so it's the better choice of the two.
The app checks both — whichever one you used is picked up automatically.
- an Environment Variable named
-
Deploy. On every startup — including after a free-tier spin-down — the app reconstructs
sessions/instagram.sessionfrom whichever source is present, so there's nothing to re-upload manually, ever, even though the filesystem itself doesn't persist.
Use this if you're already on a paid plan and prefer a real disk over an env var.
Blueprint (uses render.yaml, which already defines the disk):
push the repo, then New → Blueprint and point it at the repo. Set
INSTAGRAM_USERNAME in the dashboard (marked sync: false in
render.yaml so it's never committed).
Or manually: New → Web Service with the same build/start commands as
Option A, plus SESSION_DIR=/app/sessions. Then open the service's
Disks tab → Add Disk → mount path /app/sessions, size 1GB.
Either way, upload the session file through the Shell tab (no file-upload UI exists in the dashboard):
mkdir -p /app/sessions
echo "<paste the base64 string here>" | base64 -d > /app/sessions/instagram.sessionVerify with wc -c /app/sessions/instagram.session (should match your
local file's size), then restart the service — app.py only reads the
session file once at startup. The disk persists across deploys and
restarts, so this is a one-time step until the session eventually expires.
- Push this repo to your own GitHub account, then create a new Railway project from it.
- Railway should auto-detect the
Procfile. If not, set the start command manually to:gunicorn app:app --workers 1 --threads 4 --timeout 60 --bind 0.0.0.0:$PORT - Add a Volume in Railway and mount it at
/app/sessions— Railway's default filesystem is ephemeral and wipes on every redeploy otherwise. - Set environment variables:
INSTAGRAM_USERNAME,CACHE_TTL_SECONDS=120,SESSION_DIR=/app/sessions. - Upload your locally-generated
instagram.sessionfile into that volume (Railway shell, or a one-off deploy step) before the first real request.
If Render or Railway's logs show gunicorn listening on one port (e.g.
0.0.0.0:10000) while the platform keeps scanning a different one (e.g.
5000) forever, the start command isn't binding to the platform's $PORT
env var — it's using gunicorn's own default instead. The --bind 0.0.0.0:$PORT flag in the Procfile/render.yaml above fixes this by
making gunicorn always bind to whatever port the platform actually expects,
regardless of its value. If you copy the start command anywhere else,
keep that flag.
Follower-count caching and the Instagram session both live in this
process's memory. Gunicorn with more than one worker spins up separate OS
processes that don't share that memory — caching would silently stop
working and two workers could race over the same session. --workers 1 --threads 4 keeps everything correct in a single process while still
handling several concurrent requests via threads.
instagram-counter/
├── app.py Flask routes (/, /health, /api/followers, /api/avatar)
├── instagram_service.py Instaloader wrapper: session loading, error handling
├── cache.py In-memory TTL cache (2 min default)
├── generate_session.py Run locally once to create sessions/instagram.session
├── requirements.txt
├── Procfile Gunicorn start command (Railway/Heroku-style)
├── render.yaml Render Blueprint: service + persistent disk
├── .env.example
├── .gitignore
├── sessions/ instagram.session goes here (gitignored)
├── templates/
│ └── index.html
└── static/
├── style.css
└── script.js
| Variable | Used by | Purpose |
|---|---|---|
INSTAGRAM_USERNAME |
app.py, generate_session.py |
Which account's saved session to load |
INSTAGRAM_PASSWORD |
generate_session.py only |
One-time login when generating the session locally — never read by the running server |
CACHE_TTL_SECONDS |
app.py |
How long follower data is cached (default 120) |
SESSION_DIR |
app.py, instagram_service.py, generate_session.py |
Where the session file lives (default sessions) |
PORT |
app.py |
Port for the dev server (default 5000) |
FLASK_DEBUG |
app.py |
Set to 1 for Flask debug mode locally |