wix-media-python
The Wix Media Python SDK is useful for applications on Google App Engine and custom runtimes hosted on Google Compute Engine.
You can use Wix Media Platform in client, server, and mobile applications on various platforms and backend technologies. The Python SDK is useful for applications on Google App Engine and custom runtimes hosted on Google Compute Engine. Learn more​

Before you begin

    1.
    ​Create a Wix Media Platform account by connecting with your Google account. You can then upload media files to Wix Media Platform through the Media Manager or by using various widgets, APIs, and the Wix Media JavaScript SDK or Python SDK.
    2.
    After signing in, copy the API Key and API Secret values. You will add these to your code to authenticate with the Wix Media Platform.

Getting started with the Wix Media Platform sample app for Google App Engine

Wix Media provides a sample app that allows you to quickly try out various aspects of their SDK. The following instructions demonstrate getting the code, setting up a local development server, and running the sample:
    1.
    If you haven't already, install the App Engine SDK for Python.
    2.
    Download the Python Github project:
    1
    git clone https://github.com/wix/wixmedia-python.git
    Copied!
    or download and extract the ZIP file:
    1
    wget https://github.com/wix/wixmedia-python/archive/master.zip
    2
    unzip master.zip
    Copied!
    3.
    In the directory that you cloned or extracted the archive, copy the wix folder into the example App Engine project folder:
    1
    cd wix-media-python
    2
    cp -R wix examples/gae
    Copied!
    4.
    Edit the examples/gae/settings.py file and update the SECRET_KEY variable to contain the value from your account in the Wix Media Manager.
    5.
    Start the local App Engine development server:
    1
    [path_to_appengine_sdk]/dev_appserver.py examples/gae
    Copied!
    6.
    Launch http://localhost:8080 to view the sample app. The sample demonstrates creating thumbnails using the Wix Media Python SDK.
Use this sample app to experiment with the various methods provided by the Wix Media SDK. If you want to deploy the app, register a Google Cloud Platform project to create your App Engine project and get an application ID.

Uploading media

The following example shows how to upload an image. Replace [MY_KEY] and [MY_SECRET] with the values from your account in the Wix Media Manager.
1
from wix import media
2
​
3
client = media.Client(api_key="[MY_KEY]", api_secret="[MY_SECRET]")
4
image = client.upload_image_from_path('/files/images/cats.jpg')
5
​
6
image_id = image.get_id()
7
print image_id
Copied!
This example returns the following image ID:
1
ggl-685734655894940532967/images/ae1d86b24054482f8477bfbf2d426936/cats.jpg
Copied!

Rendering thumbnails

The following example is an App Engine application handler. Using Django templates, the handler renders an HTML page with two thumbnails:
1
class RenderImagesHandler(webapp2.RequestHandler):
2
def get(self):
3
# Image id's can be fetched from datastore ...
4
image_ids = [
5
'ggl-685734655894940532967/images/ae1d86b24054482f8477bfbf2d426936/cat.jpg',
6
'ggl-685734655894940532967/images/c074a4a8ea854ee7b5b893ce2a0c7361/dog.jpg'
7
]
8
​
9
context = {
10
'thumbnail_urls': [
11
RenderImagesHandler.create_image_thumbnail_url(image_id) for image_id in image_ids
12
]
13
​
14
self.response.headers['Content-Type'] = 'text/html'
15
self.response.out.write(render_to_string('example.html', context))
16
​
17
@staticmethod
18
def create_image_thumbnail_url(image_id):
19
client = media.Client()
20
image = client.get_image_from_id(image_id)
21
​
22
return image.srz(width=120, height=120).get_url()
Copied!

Additional resources

Last modified 7mo ago