Secure video player for Django and Flask

Built your course site with Django or Flask? Fetch a token in the lesson view and show the secure player in your template.

Why XAPlayer for Python

  • Django and Flask

    The tutorial covers both; FastAPI or any other framework needs the same single request.

  • Key in settings

    The key stays in settings or an environment variable that only the server sees.

  • Your own access control

    Sign-in and purchase checks use login_required and your own models.

  • User name on the video

    The Django or Flask user’s full name becomes the watermark.

Three steps to secure playback

  1. Put the API key in your project settings.
  2. In the lesson view, after the access check, get a token with requests.
  3. Show the player URL in an iframe in the template.

Tutorials and docs

A taste of the code

The full code, where it goes and how to test it are in the tutorial.

views.py
res = requests.post(
    f"{settings.XAPLAYER_URL}/embed-tokens",
    headers={"Authorization": f"Bearer {settings.XAPLAYER_API_KEY}"},
    json={"courseId": course.xaplayer_id,
          "viewer": {"id": str(request.user.id), "name": request.user.get_full_name()}},
    timeout=10,
)
return render(request, "watch.html", {"url": res.json()["url"]})

Questions

Just requests, or httpx for async.

Yes. The same request works with httpx in an async endpoint.

Four hours by default, adjustable from one minute to 24 hours.

The API key is wrong or revoked; create a new one in the panel and replace it.

Other platforms

Protect your course today

Signing up takes two minutes. 14 days free, with 10 licenses on us.

Start your 14-day free trial