Making Apps using Python, Django and App Engine

We recently announced the release of our Python adaptor for the Shopify API. Now we would like to inform you that we have got it working well with the popular Django web framework and Google App Engine hosting service. But don't just take my word for it, you can see a live example on App Engine and check out the example's source code on GitHub. The example application isn't limited to Google App Engine, it can run as a regular Django application allowing you to explore other hosting options.

The shopify_app directory in the example contains the reusable Django app code. This directory contains views for handling user login, authentication, and saves the Shopify session upon finalization. Middleware is included which loads session to automatically re-initialize the Python Shopify API for each request. There is also a @shop_login_required decorator for view functions that require login, which will redirect logged out users to the login page. As a result, your view function can be as simple as the following to display basic information about the shop's products and orders.

@shop_login_required
def index(request):
    products = shopify.Product.find(limit=3)
    orders = shopify.Order.find(limit=3, order="created_at DESC")
    return render_to_response('home/index.html', {
        'products': products,
        'orders': orders,
    }, context_instance=RequestContext(request))

Getting Started for Regular Django App

  1. Install the dependancies with this command:
    easy_install Django ShopifyAPI PyYAML pyactiveresource
  2. Download and unzip the zip file for the example application

Getting Started for Google App Engine

  1. Install the App Engine SDK
  2. Download and unzip the example application zip file for App Engine which includes all the dependancies.
  3. Create an application with Google App Engine, and modify the application line in app.yaml with the application ID registered with Google App Engine.

Develop

    1. Create a Shopify app through the Shopify Partner account with the Return URL set to http://localhost:8000/login/finalize, and modify shopify_settings.py with the API-Key and Shared Secret for the app.
    2. Start the server:
      python manage.py runserver
    3. Visit http://localhost:8000 to view the example.
    4. Modify the code in the home directory.

    Deploy

    1. Update the return URL in your Shopify partner account to point to your domain name (e.g. https://APPLICATION-ID.appspot.com/login/finalize)
    2. Upload the application to the server. For Google App Engine, simply run:
      appcfg.py update .

    Further Information

    Update: Extensive examples on using the Shopify Python API have been added to the wiki.