Tutorials · 2 min read

Progressive uploads with the api.video Python client

Learn how to do a progressive video upload using the Python client and api.video.

Erikka Innes

December 15, 2021

Today we'll walk through how to use the Python client to do a progressive upload for a video. Progressive uploads are great for large videos. We recommend choosing this type of upload if your video is 200MB or greater.

Prerequisites

  • Sign up for an api.video account - https://dashboard.api.video/register
  • Set up a virtual environment for your project (optional)
  • Install the api.video Python client - pip install api.video
  • Get a video file that's 200MB or greater (you can use a smaller one to see how it works, but it should be at least around 50MB)

Code sample

Here's our code sample for today:

python

In this sample we do the following:

  1. Set up the API client.
  2. Create a container for our video with a payload containing our video metadata.
  3. Retrieve the video ID from the new container we made.
  4. Create a session to handle our progressive video upload using the video ID we retrieved.
  5. Set the chunk size we want to use. This value will be used to create chunks of this size. It's set to a smaller number so you can demo with a smaller video. If you want to upload something bigger, you might want to use a bigger number for each chunk.
  6. Set up a method that handles breaking the video into chunks of data.
  7. Set up a progressive video uploader. Of note - you have to take each chunk of data and save it as a clearly numbered part. For example chunk_file.part.1, chunk_file.part.2. End the files with part.* so that the api.video server can figure out the chronological order for each chunk of video. Also of note - you must signal that you're uploading the last chunk of video with the session.uploadLastPart() method. Otherwise, the api.video servers cannot determine if you're still uploading or not, so your upload will fail. You also have to open your file after saving it, using 'rb' or read binary.

Conclusion

If you want to try this upload without the client, see the article about how to do a progressive upload with just Python.

Happy coding!

Try out more than 80 features for free

Access all the features for as long as you need.
No commitment or credit card required

Video API, simplified

Fully customizable API to manage everything video. From encoding to delivery, in minutes.

Built for Speed

The fastest video encoding platform. Serve your users globally with 140+ points of presence. 

Let end-users upload videos

Finally, an API that allows your end-users to upload videos and start live streams in a few clicks.

Affordable

Volume discounts and usage-based pricing to ensure you don’t exceed your budget.