Package: wystia
Wystia - Wistia API HelperA Python wrapper library for the Wistia APIFree software: MIT licenseDocumentation:https://wystia.readthedocs.io.Wistia Developer Docs:https://wistia.com/support/developers.InstallationThe Wystia library is availableon PyPI, and can be installed withpip:$pipinstallwystiaYou’ll also need to create an access token as outlinedin the docs.UsageSample usage with theData API:Note: The following example makes use ofWistiaApi, which is an alias to
the classWistiaDataApi.fromwystiaimportWistiaApifromwystia.modelsimportSortBy,LanguageCode,Customizations,Private# Setup the Wistia API token to use for requests. You can alternatively# set this via the env variable 'WISTIA_API_TOKEN'.WistiaApi.configure('MY-TOKEN')# Retrieve a list of all projects in the Wistia account,# sorted A-Z and in ascending order.projects=WistiaApi.list_all_projects(SortBy.NAME)project_ids=[p.hashed_idforpinprojects]# Print the project data as a prettified JSON stringprint(projects.prettify())# 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=WistiaApi.list_videos('project-id')# Retrieve info on a particular videovd=WistiaApi.get_video('video-id')# If the video has captions, that won't be included in the `Medias#show`# response by default, so we'll need a separate API call as below.# vd.process_captions(#     WistiaApi.list_captions(real_video_id))print(vd)# Update attributes on a media (video), or set a custom thumbnail on the video.WistiaApi.update_video('video-id',thumbnail_media_id='uploaded-thumbnail-id')# Get aggregated stats for a video, such as view countstats=WistiaApi.get_stats_for_video('video-id')# Retrieve the customization data for a videocustomizations=WistiaApi.get_customizations('video-id')# Update only specific customizations for a video# Note the embed options are documented here:#   https://wistia.com/support/developers/embed-optionssample_embed_options=Customizations(player_color='#e7fad1',# Hide comments on the media pageprivate=Private(show_comments=False))WistiaApi.update_customizations('video-id',sample_embed_options)# Get the Spanish captions on a videocaptions=WistiaApi.get_captions('video-id',LanguageCode.SPANISH)# Add (or replace) the English captions on a videoWistiaApi.update_captions('video-id',LanguageCode.ENGLISH,srt_file='path/to/file.srt')… or to upload media via theUpload API:fromwystiaimportWistiaUploadApi# Upload a file to a (default) project on Wistiar=WistiaUploadApi.upload_file('path/to/my-file.mp4')# Check if the video was successfully uploaded# assert r.created# assert r.name == 'my-file.mp4'# 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:fromwystiaimportWistiaEmbedApi# Get the media embed dataembed_data=WistiaEmbedApi.get_data('video-id')# Retrieve the source URL of the original mediasource_url=WistiaEmbedApi.asset_url(media_data=embed_data)… when using theData API, theWistiaHelpercan help to further simplify some calls:fromwystiaimportWistiaHelper# Check if the video exists in your Wistia accountassertWistiaHelper.video_exists('abc1234567')# 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-toolsassertWistiaHelper.is_archived_video('My Title [Archived on August 13, 2015]')# Update the player color on a videoWistiaHelper.customize_video_on_wistia('video-id','ffffcc')# Individually enable captions / AD in the player for a videoWistiaHelper.enable_ad('video-id')WistiaHelper.enable_captions('video-id',on_by_default=False)# Disable captions / AD in the player for a videoifWistiaHelper.has_captions_enabled('video-id'):print('Disabling captions and AD for the video')WistiaHelper.disable_captions_and_ad('video-id')Getting StartedUsing 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_TOKENAnother option is to use the globalconfiguremethod as shown below:WistiaDataApi.configure('MY-API-TOKEN')There is additionally aQuickstartsection in the docs which walks
through - in more detail - how to get up and running with the
Wystia library.Data APIThe wrapper classWistiaDataApi(aliased toWistiaApi) interacts
with the Wistia Data API (docs below):https://wistia.com/support/developers/data-apiIt fully implements the following sections in the API documentation:Paging and Sorting ResponsesProjectsMediasCustomizationsCaptionsThe following sections in the API havenotbeen implemented (mainly as I haven’t used them before):Project SharingsAccountTipsContainersIn general, the API methods that begin withlist- such aslist_project-
will return aContainerobject, which essentially acts as a thin wrapper
around a collection of model classes. For all intents and purposes, this behaves
exactly the same as alistobject.One of the main benefits is that it implements a__str__method, which leverages
the builtinpprintmodule in Python to pretty-print the Python object representation
of each model ordataclassinstance; this will format the output more nicely, for example
wheneverprint(obj)is called on theContainerresult.TheContainerobjects also implement the following convenience methods, which can
be used to easily display the JSON string representation of the list of dataclass instances:to_json- Convert the list of instances to a JSON string.prettify- Convert the list of instances to aprettifiedJSON string.List Medias in a ProjectIf you need to retrieve info on videos in a project and you
don’t need complete info such as a list of assets for the video,
I recommend usinglist_projectinstead oflist_videos. This is because
theProjects#showAPI returns up to 500 results per request, whereas theMedias#listonly returns the default 100 results per page.Assuming a project in your Wistia account has a total of about 250 media, here is the number of API
calls you might expect from each individual approach:fromwystiaimportWistiaDataApivideos=WistiaDataApi.list_videos('project-id')assertWistiaDataApi.request_count()==3# Resets request count for the next callWistiaDataApi.reset_request_count()videos=WistiaDataApi.list_project('project-id')assertWistiaDataApi.request_count()==1Thread SafetyThe Wistia API classes are completely thread safe, sincerequests.Sessionobjects are not re-used between API calls.This means that if you have two (un-related) API operations to perform,
such as updating a video’s title and adding captions on the video,
then you can certainly run those calls in parallel so that
they complete a bit faster.CreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History1.2.2 (2023-04-14)Features and ImprovementsUpdatekeywordsfor the package.AddPython 3.11to the list of supported versions.1.2.1 (2023-04-14)BugfixesTheMediaclass did not have thearchived(bool) field, which
was resulting in errors whenlist_project()was called.Therefore, moved over this field fromVideotoMediainstead (which is the
super-class) so that this issue can be resolved.1.2.0 (2023-04-07)Features and ImprovementsUpdate model classes to supportnewpopulated fields, such asarchived(aboolfield), as otherwise it breaks de-serialization by default – credits to@KaneDM.Upgrade dependencies inrequirements-dev.txt.BugfixesUpdate to replace plaindictannotation withdict[str, str], as previously it was resulting in errors when parsing the class annotations.1.1.0 (2022-01-27)Features and ImprovementsRefactor any model classes that would be returned inlistAPI
calls to subclass fromJSONListWizardinstead ofJSONWizard,
simply so thatContainerobjects will be returned by default.Refactor to importContainerfrom thedataclass-wizardlibrary
instead. For backwards compatibility reasons, themodelsmodule
still exports theContainernamespace.1.0.0 (2022-01-14)Breaking ChangesWystia has officially dropped support for Python versions 3.5 and 3.6.
The support for 3.6 needed to be dropped primarily because of thefrom __future__ import annotationsusage in the code.Refactored all API helper classes to return model class objects as a result,
rather than Pythondictobjects. In the case of anylist- related API responses,
we now return aContainerobject so that it can be easier to print or display
the result for debugging purposes.All inputs to the API helper methods that previously accepted adictobject,
have in general been refactored to accept a model dataclass instance as an input instead.Renamed some error classes; for example,NoSuchMediainstead ofNoSuchVideo.Renamed some model classes; for example,MediaStatusinstead ofVideoStatus.Features and ImprovementsAddedWistiaApito the list of public exports, which is aliased to theWistiaDataApihelper class.Added new methods to theWistiaDataApiclass for more explicitly
interacting withmediasinstead ofvideos. For example, alist_mediasmethod is added as an alternative to callinglist_videos.Refactored the CI process to use GitHub Workflows instead of Travis CI.Added3.10to the list of supported Python versions.Updated the project status fromBetatoProduction/Stable.Added anexamples/folder in the project repo on GitHub, which
contains Python scripts to demonstrate sample usage.Updated docs and added a newQuickstartsection.0.3.0 (2021-07-21)Features and ImprovementsAdd compatibility changes to extend support to Python 3.5 and 3.6WistiaHelper: Add methodproject_detailsto retrieve info on a particular Wistia projectWistiaEmbedApi: Update to parse the.jsonresponse rather than the.jsonpversionMakefile: Add new commandinit, which can be used to install Dev dependencies for the projectEnsure the new command is compatible with Python 3.5, which has dependencies on separate
package versions; here we should userequirements-py35-dev.txtinstead.Makefile: Updatecoveragecommand to run unit tests by defaultBugfixesmodels.VideoData: The parameter to theprocess_captionsmethod is now
correctly type-annotated to accept aListofDict0.2.1 (2021-06-17)WistiaHelper: Add methodenable_captions_and_adRemove.formatusage in log statementsRemove an unnecessary methodad_neededfromVideoDataUpdate readme and Sphinxdocs/0.2.0 (2021-06-16)Fully implement all sections in the Wistia Data APIAdd more methods to theWistiaHelperclassRequest Count and API Token should now be globally shared by all API sub-classesLot of code refactoringExclude.mp4files from dist, to reduce total package sizeAdd more test casesUpdate docs with better examples0.1.0 (2021-06-12)First release on PyPI.