Skip to content

zencoder/zencoder-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zencoder

Build Status

A Python module for interacting with the Zencoder API.

Getting Started

Install from PyPI

$ pip install zencoder

Import zencoder

from zencoder import Zencoder

Create an instance of the Zencoder client. This will accept an API key and version. If not API key is set, it will look for a ZENCODER_API_KEY environment variable. API version defaults to 'v2'.

# If you want to specify an API key when creating a client
client = Zencoder('API_KEY')

# If you have the environment variable set
client = Zencoder()

Create a new job.

client.job.create('s3://bucket/key.mp4')
client.job.create('s3://bucket/key.mp4',
               outputs=[{'label': 'vp8 for the web',
                         'url': 's3://bucket/key_output.webm'}])

This returns a zencoder.Response object. The body includes a Job ID, and one or more Output IDs (one for every output file created).

response = client.job.create('s3://bucket/key.mp4')
response.code           # 201
response.body['id']     # 12345

List jobs.

By default the jobs listing is paginated with 50 jobs per page and sorted by ID in descending order. You can pass two parameters to control the paging: page and per_page.

client.job.list(per_page=10)
client.job.list(per_page=10, page=2)

Get details about a job.

The number passed to details is the ID of a Zencoder job.

client.job.details(1)

Get progress on a job.

The number passed to progress is the ID of a Zencoder job.

client.job.progress(1)

Resubmit a job

The number passed to resubmit is the ID of a Zencoder job.

client.job.resubmit(1)

Cancel a job

The number passed to cancel is the ID of a Zencoder job.

client.job.cancel(1)

Get details about an input.

The number passed to details is the ID of a Zencoder input.

client.input.details(1)

Get progress for an input.

The number passed to progress is the ID of a Zencoder input.

client.input.progress(1)

Get details about an output.

The number passed to details is the ID of a Zencoder output.

client.output.details(1)

Get progress for an output.

The number passed to progress is the ID of a Zencoder output.

client.output.progress(1)

Reports are great for getting usage data for your account. All default to 30 days from yesterday with no grouping, but this can be altered. These will return 422 Unprocessable Entity if the date format is incorrect or the range is greater than 2 months.

Get all usage (Live + VOD).

import datetime
client.report.all()
client.report.all(grouping="foo")
client.report.all(start_date=datetime.date(2011, 10, 30),
                end_date=datetime.date(2011, 11, 24))
client.report.all(start_date=datetime.date(2011, 10, 30),
                end_date=datetime.date(2011, 11, 24),
                grouping="foo")

Get VOD usage.

import datetime
client.report.vod()
client.report.vod(grouping="foo")
client.report.vod(start_date=datetime.date(2011, 10, 30),
               end_date=datetime.date(2011, 11, 24))
client.report.vod(start_date=datetime.date(2011, 10, 30),
               end_date=datetime.date(2011, 11, 24),
               grouping="foo")

Get Live usage.

import datetime
client.report.live()
client.report.live(grouping="foo")
client.report.live(start_date=datetime.date(2011, 10, 30),
                end_date=datetime.date(2011, 11, 24))
client.report.live(start_date=datetime.date(2011, 10, 30),
                end_date=datetime.date(2011, 11, 24),
                grouping="foo")

Create a new account. A unique email address and terms of service are required, but you can also specify a password (and confirmation) along with whether or not you want to subscribe to the Zencoder newsletter. New accounts will be created under the Test (Free) plan.

No API Key is required.

client.account.create('[email protected]', tos=1)
client.account.create('[email protected]', tos=1,
                   options={'password': 'abcd1234',
                            'password_confirmation': 'abcd1234',
                            'affiliate_code': 'foo'})

Get details about the current account.

client.account.details()

Turn integration mode on (all jobs are test jobs).

client.account.integration()

Turn off integration mode, which means your account is live (and you'll be billed for jobs).

client.account.live()

Tests

The tests use the mock library to stub in response data from the API. Run tests individually:

$ python test/test_jobs.py

Or use nose:

$ nosetests