Skip to main content

A Python wrapper library for the Wistia API

Project description

Wistia API Helper

https://img.shields.io/pypi/v/wystia.svg https://img.shields.io/pypi/l/wystia.svg https://img.shields.io/pypi/pyversions/wystia.svg https://img.shields.io/travis/rnag/wystia.svg Documentation Status Updates

A Python wrapper library for the Wistia API

Usage

Sample usage with the Data API:

from wystia import WistiaDataApi
from wystia.models import SortBy, LanguageCode, VideoData

# Retrieve a list of all projects in the Wistia account,
# sorted A-Z and in ascending order.
projects = WistiaDataApi.list_all_projects(SortBy.NAME)
project_ids = [p['hashedId'] for p in projects]

# Retrieve a list of videos for a Wistia project.
# Note: If you don't require asset info (such as ADs) on each
#   video, I suggest calling `list_project` instead.
videos = WistiaDataApi.list_videos('project-id')

# Retrieve info on a particular video
video_dict = WistiaDataApi.get_video('video-id')
vd = VideoData(**video_dict)
print(vd)

# Update attributes on a media (video), or set a custom thumbnail on the video.
WistiaDataApi.update_video(
    'video-id', thumbnail_media_id='uploaded-thumbnail-id')

# Get aggregated stats for a video, such as view count
stats = WistiaDataApi.get_stats_for_video('video-id')

# Retrieve the customization data for a video
customizations = WistiaDataApi.get_customizations('video-id')

# Update only specific customizations for a video
# Note the embed options are documented here:
#   https://wistia.com/support/developers/embed-options
WistiaDataApi.update_customizations('video-id',
                                    {'playerColor': '#e7fad1',
                                     # Hide comments on the media page
                                     'private': {'show_comments': 'false'}})

# Get the Spanish captions on a video
WistiaDataApi.get_captions('video-id', LanguageCode.SPANISH)

# Add (or replace) the English captions on a video
WistiaDataApi.update_captions('video-id', LanguageCode.ENGLISH,
                              srt_file='path/to/file.srt')

… or to upload media via the Upload API:

import os
from wystia import WistiaUploadApi

# Upload a file to a (default) project on Wistia
r = WistiaUploadApi.upload_file('path/to/my-file.mp4')
expected_name = os.path.basename('path/to/my-file.mp4')

assert r.created
assert r.name == expected_name

# Uploads with a public link to a video, such as
# an S3 pre-signed url.
r = WistiaUploadApi.upload_link('my-s3-link',
                                title='My Video Name',
                                description='My Description')

… you can alternatively retrieve asset info via the public Media Embed link:

from wystia import WistiaEmbedApi

# Get the media embed data
embed_data = WistiaEmbedApi.get_data('video-id')

# Retrieve the source URL of the original media
source_url = WistiaEmbedApi.asset_url(media_data=embed_data)

… When using the Data API, the WistiaHelper can help to simplify some calls:

from wystia import WistiaHelper

# Check if the video exists in your Wistia account
if WistiaHelper.video_exists('abc1234567'):
    print('My video exists!')

# Check if a video's name indicates the video is an archived copy of an
# existing video, as discussed in the below article on replacing a media:
#   https://wistia.com/learn/product-updates/improved-library-management-tools
if WistiaHelper.is_archived_video('My Title [Archived on August 13, 2015]'):
    print('This video is archived!')

# Update the player color on a video
WistiaHelper.customize_video_on_wistia('video-id', 'ffffcc')

# Enable captions / AD in the player for a video
WistiaHelper.enable_ad('video-id')
WistiaHelper.enable_captions('video-id', on_by_default=False)

# Disable captions / AD in the player for a video
if WistiaHelper.has_captions_enabled('video-id'):
    print('Disabling captions and AD for the video')
    WistiaHelper.disable_captions_and_ad('video-id')

Installing Wystia and Supported Versions

The Wystia (Wistia helper) library is available on PyPI:

$ python -m pip install wystia

The wystia library officially supports Python 3.7 or higher.

Getting Started

Using the methods on the API classes assume your Wistia API token has previously been configured, for example via the environment. The API token will then be used globally by all the API classes when making requests to the Wistia API.

You can set the following environment variable with your API token:

  • WISTIA_API_TOKEN

Another option is to use the global configure method as shown below:

WistiaDataApi.configure('MY-API-TOKEN')

Data API

The wrapper class WistiaDataApi interacts with the Wistia Data API (docs below):

It fully implements the following sections in the API documentation:

  • Paging and Sorting Responses

  • Projects

  • Medias

  • Customizations

  • Captions

The following sections in the API have not been implemented (mainly as I haven’t used them before):

  • Project Sharings

  • Account

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.2.0 (2021-06-16)

  • Fully implement all sections in the Wistia Data API

  • Add more methods to the WistiaHelper class

  • Request Count and API Token should now be globally shared by all API sub-classes

  • Lot of code refactoring

  • Exclude .mp4 files from dist, to reduce total package size

  • Add more test cases

  • Update docs with better examples

0.1.0 (2021-06-12)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wystia-0.2.0.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

wystia-0.2.0-py2.py3-none-any.whl (26.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file wystia-0.2.0.tar.gz.

File metadata

  • Download URL: wystia-0.2.0.tar.gz
  • Upload date:
  • Size: 31.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.0

File hashes

Hashes for wystia-0.2.0.tar.gz
Algorithm Hash digest
SHA256 82ecc89d4df7ff41cb7759357aad506efbfd67d678e9ea98f0d2551385307a6d
MD5 d7a49656d890d18d3df7f8d24a59d1b5
BLAKE2b-256 95aa34bba63d0c5fb6a9be451ca64c41da10b984dbe41f3c15f2c6d2908aadc6

See more details on using hashes here.

File details

Details for the file wystia-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: wystia-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.7.0 requests/2.25.1 setuptools/57.0.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.0

File hashes

Hashes for wystia-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ba9a766adf06567d71a3a2996658ec203eef7c68597e9e9a60a0786998fde54d
MD5 2e6e3a7620c0fae22f4c5a5e488025a2
BLAKE2b-256 53d714d9f565a997c8f92669fd9690c7335541f1c836adbe71d361527bf47a7a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page