Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tomconte/videoindexer-samples-python
Python samples for Azure Video Indexer
https://github.com/tomconte/videoindexer-samples-python
azure python
Last synced: about 1 month ago
JSON representation
Python samples for Azure Video Indexer
- Host: GitHub
- URL: https://github.com/tomconte/videoindexer-samples-python
- Owner: tomconte
- License: mit
- Created: 2022-02-11T16:51:11.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-04T14:20:38.000Z (over 2 years ago)
- Last Synced: 2024-10-06T17:06:17.883Z (about 1 month ago)
- Topics: azure, python
- Language: Python
- Homepage:
- Size: 279 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Azure Video Indexer Python samples
This repository contains some examples showing how to access the REST API of [Azure Video Indexer](https://docs.microsoft.com/en-us/azure/azure-video-indexer/) from Python.
The samples use a SDK generated from the Video Indexer Swagger API definition. You can browse the [`videoindexer`](videoindexer) directory to read the full generated API documentation.
The dependencies are managed using [Poetry](https://python-poetry.org/), you should have that tool installed on your machine. If you prefer to use `requirements.txt`, you can generate one using Poetry: `poetry export -o requirements.txt`.
## Use the examples
To use the samples, first install the dependencies using Poetry. You don't need to build the SDK, the samples will use the SDK included in the repository.
```sh
poetry install
```The examples rely on a small helper library to retrieve an AVAM access token. This libray uses the `DefaultAzureCredential` class in the [azure-identity](https://docs.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python) library to authenticate with Azure Active Directory. This class can use a number of different schemes to determine the identity to use for authentication: environment variables, user/system assigned managed identities, etc.
For example, if you want to use a Service Principal to authenticate, you can define the following environment variables:
```sh
export AZURE_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export AZURE_CLIENT_SECRET=123random456string
export AZURE_TENANT_ID=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
```If you are logged in using the Azure CLI tool, `DefaultAzureCredential` will use your current credentials.
In addition, to access the AVAM API, the following environment variables will be used:
```sh
export AVAM_SUBSCRIPTION=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export AVAM_RESOURCE_GROUP=foo
export AVAM_ACCOUNT_ID=yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
export AVAM_ACCOUNT_NAME=bar
export AVAM_LOCATION=eastus
```- `AVAM_SUBSCRIPTION` is the Azure subscription ID where the AVAM account was created.
- `AVAM_RESOURCE_GROUP` is the name of the Resource Group where the AVAM account was created.
- `AVAM_ACCOUNT_ID` is the AVAM account ID, it can be found for example on the AVAM resource "Overview" page in the portal.
- `AVAM_ACCOUNT_NAME` is the AVAM account name, as specified when it was created.
- `AVAM_LOCATION` is the datacenter location of the AVAM account.You can then run an example:
```sh
poetry run python list_videos.py
```## List of examples
All the samples use a helper function `list_all_videos()` in `utils.py` to retrieve all the videos using the API paging mechanism.
- `list_videos.py`: list the names of all videos.
- `download_all_thumbnails.py`: download all keyframe thumbnails for all videos.
- `download_all_insights.py`: download insights JSON document for all videos.
- `delete_videos.py`: delete videos.## Generate the SDK
Here are the steps you can follow if you want to re-generate the SDK for any reason.
The SDK is generated using a [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) Docker image, so you should have Docker installed and runnning on your machine.
You can generate the SDK in the `scripts` directory:
```sh
cd scripts
poetry install
poetry run bash build_sdk.sh
```The SDK is generated in the `videoindexer` directory. If you want to use it in the samples, you will have to move it into place (one directory up).