Django: download YouTube, TikTok and Instagram videos
In Django, keep the CrawlFetch call in a small service module, call it from a view for instant results, and from a Celery task when you need to save the file.
How it fits together
A view resolves the URL and renders the result; a Celery task downloads downloadUrl into a FileField so the request returns immediately.
Django example
import osimport requestsSESSION = requests.Session()SESSION.headers["Authorization"] = f"Bearer {os.environ['CRAWLFETCH_KEY']}"def resolve(url: str) -> dict:r = SESSION.get("https://api.crawlfetch.com/v1/resolve", params={"url": url}, timeout=15)r.raise_for_status()return r.json()
Notes for Django
- Read the key from the environment (or django-environ), never
settings.pyin git. retry_backoff=Truegives exponential backoff for 429 and 500 responses.- Point
FileFieldstorage at S3 (django-storages) for production.
FAQ
Can I store downloaded files in S3?
Yes — use django-storages so video.file.save uploads to your bucket.
Related
Last updated 2026-10-25