Automatically refresh Instagram cookies using Selenium, save them in Netscape HTTP Cookie File format, and expose healthcheck and readiness endpoints via Flask. Designed for Dockerized, production-like deployments with Python.
Works well together with yt-dlp, gallery-dl or bots like ovchynnikov/load-bot-linux.
- Python 3.13 support
- Periodic auto-refresh of cookies
- Exports cookies compatible with cURL and other tools
- Uses headless Firefox browser
- Full Docker and Docker Compose support
- Health monitoring via
/statusand/healthzendpoints - Manual PR-based image build via GitHub Actions for debugging
-
Dependency: Python 3.13
-
Create Python virtualenv (required during first run):
mkdir -p "${HOME}/.local/virtualenv" && \ python3.13 -m venv ~/.local/virtualenv/instagram-cookie-generator && \ source "${HOME}/.local/virtualenv/instagram-cookie-generator/bin/activate" && \ pip install --upgrade pip
-
Activate virtualenv:
source "${HOME}/.local/virtualenv/instagram-cookie-generator/bin/activate"
-
Install dependencies:
pip install -e '.[dev]' -
Verify installed tools:
black --version && \ echo -n "isort " && isort --version-number && \ mypy --version && \ pylint --version
-
Prepare environment variables:
Copy
.env.exampleto.envand edit your credentials:cp .env.example .env
-
Run the container:
docker compose up
-
Healthcheck integration:
Docker Compose is configured with a healthcheck using the
/healthzendpoint:healthcheck: test: ["CMD", "curl", "-f", "http://localhost:5000/healthz"] interval: 2m timeout: 10s retries: 3
Make targets are self-documented.
List all available targets:
make helpTypical examples:
make code-checks— Run full code quality checksmake hooks-install— Install pre-commit hooks
This repository uses pre-commit to enforce code quality before each commit.
To install hooks:
make hooks-installSee configured checks inside .pre-commit-config.yaml.
After startup, the Flask server exposes two health endpoints:
| Endpoint | Purpose |
|---|---|
GET /status |
Returns rich cookie metadata: TTL, names, updated timestamp, version |
GET /healthz |
Returns 200 only if cookies are valid and not expired |
Example usage:
curl http://127.0.0.1:5000/status
curl http://127.0.0.1:5000/healthzYou can manually trigger a Docker image build and push to GHCR from any Pull Request. Useful for debugging changes before merging.
The workflow can be run from the Actions tab by selecting Manual PR Image Build and clicking "Run workflow".
Tag format: ghcr.io/vovinacci/instagram-cookie-generator:pr-<PR_NUMBER>
| Tool | Purpose |
|---|---|
black |
Code formatting |
isort |
Import sorting |
mypy |
Static type checking |
pylint |
Static linting |
All tools are integrated via Makefile and pre-commit hooks.
- Dockerfile uses unpinned apt packages for simplicity; pinning can be added for strict reproducibility if needed.
- Logger supports both plain and JSON formats (configurable via
.env).