crawlfetch

Flask: download YouTube, TikTok and Instagram videos

Many "YouTube downloader in Flask" tutorials embed pytube and break within weeks. Swapping the extraction for one CrawlFetch call keeps the Flask app tiny and stable.

How it fits together

A single route takes the URL from a form, resolves it server-side and renders a download link. No media is processed inside the Flask process.

Flask example

import os
import requests
from flask import Flask, render_template_string, request
app = Flask(__name__)
PAGE = """
<form method=post><input name=url placeholder="Video URL"><button>Resolve</button></form>
{% if video %}<p>{{ video.title }}</p><a href="{{ video.downloadUrl }}">Download</a>{% endif %}
{% if error %}<p>{{ error }}</p>{% endif %}
"""
@app.route("/", methods=["GET", "POST"])
def index():
if request.method == "GET":
return render_template_string(PAGE)
r = requests.get(
"https://api.crawlfetch.com/v1/resolve",
params={"url": request.form["url"]},
headers={"Authorization": f"Bearer {os.environ['CRAWLFETCH_KEY']}"},
timeout=15,
)
if not r.ok:
return render_template_string(PAGE, error=f"Could not resolve ({r.status_code})")
return render_template_string(PAGE, video=r.json())

Notes for Flask

  • Add Flask-Limiter to stop abuse of a public form.
  • Use render_template with a real template file in production.

FAQ

Is this better than a pytube Flask app?

It removes the part that breaks. See pytube alternative.

Related

Last updated 2026-10-25

Add video downloads to your product today.

1,000 credits on signup plus 500 every month. That is roughly 180 YouTube clips to start, with no card.

Create free account