Page Contents

    Python Code

    This topic provides a sample Python script for ingesting a video using the Dynamic Ingest API.


    REST APIs like the Brightcove platform APIs can be used with any language. The Python script included here is just one sample to show you how requests are put together. There is another sample of a simple GET request (for the CMS API) here.


    Python script

    The code below shows the script. Note that to use it, you will need to supply your own values for the following:

    • ***ACCOUNT ID HERE**** (line 8)
    • ***CLIENT ID HERE**** (line 9)
    • ***CLIENT SECRET HERE**** (line 10)
    • ***VIDEO TITLE HERE*** (line 27)
    • ***SOURCE VIDEO URL HERE*** (line 40)
        #!/usr/bin/env python
        import sys
        import requests
        import json
        import argparse
        pub_id = "***ACCOUNT ID HERE****"
        client_id = "***CLIENT ID HERE****"
        client_secret = "***CLIENT SECRET HERE****"
        access_token_url = ""
        profiles_base_url = "{pubid}/profiles"
        def get_access_token():
            access_token = None
            r =, params="grant_type=client_credentials", auth=(client_id, client_secret), verify=False)
            if r.status_code == 200:
                access_token = r.json().get('access_token')
            return access_token
        def create_video():
            access_token = get_access_token()
            headers = { 'Authorization': 'Bearer ' + access_token, "Content-Type": "application/json" }
            url = ("{pubid}/videos/").format(pubid=pub_id)
            data = '{"name": "***VIDEO TITLE HERE***"}'
            r =, headers=headers, data=data)
            return r.json()
        def submit_pbi(video_id):
            access_token = get_access_token()
            print access_token
            headers = { 'Authorization': 'Bearer ' + access_token, "Content-Type": "application/json" }
            url = ("{pubid}/videos/{videoid}/ingest-requests").format(pubid=pub_id, videoid=video_id)
            print url
            data = '''{
                    "master": { "url": "****SOURCE VIDEO URL HERE***" }
            r =, headers=headers, data=data)
            print r.headers
            return r.json()
        v = create_video()
        print v
        print submit_pbi(v['id'])

    Page last updated on 28 Sep 2020