MindTouch Developer Center > Deki > FAQ > Extensions > How do I...Write an extension using Google App Engine?

How do I...Write an extension using Google App Engine?

Creating an extension with Google App Engine is incredibly simple:

  1. Download the App Engine SDK
  2. Create a new application
  3. Add the DekiExt.py file to it

google-app-engine.png

Creating your own extension only takes a few lines of code:

#!/usr/bin/env python

import cgi
import wsgiref.handlers

from google.appengine.api import users
from google.appengine.ext import webapp

from dekiext import *

class MyExtension(DekiExt):

	# this method is required
	def title(self): return "My Extension"

	# the following methods are optional
	def description(self): return "My Description"
	def namespace(self): return "my"
	def copyright(self): return "My Copyright"
	def label(self): return "MyExt"

	# function to export
	@function("str", "return user greeting")
	@param("str", "name of user (default: \"stranger\")", True)
	def hello(self, name):
		return "Hi " + (name or "stranger!")

def main():
	application = webapp.WSGIApplication([('/', MyExtension)], debug=True)
	wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
	main()

Upload it to your account.  Now try it out by going to your application's URI. (e.g. http://dekiext.appspot.com)

<extension>
  <title>My Extension</title>
  <copyright>My Copyright</copyright>
  <description>My Description</description>
  <namespace>my</namespace>
  <function>
    <name>hello</name>
    <description>return user gretting</description>
    <uri protocol="xmlrpc">http://dekiext.appspot.com/hello.rpc</uri>
    <param name="name" type="str" optional="true">name of user (default: "stranger")</param>
    <return type="str" />
  </function>
</extension>

To add your newly created extension to Deki Wiki, follow these steps:

  1. Open your Control Panel
  2. Click on Service Management
  3. Click on Remote
  4. Select Extension from the dropdown menu
  5. Enter a description for your extension
  6. Paste in the URI
  7. And click Add Service

Your users can now invoke extension functions directly from your Google App Engine application.


Reference

The DekExt module relies on one class (DekiExt) and two decorator methods (@function and @param).

DekiExt

Your class MUST derive from the DekiExt class.  You can then decorate methods you want to export with @function.

Your class MUST implement the title() method.  The title() method returns the full name for your extension.

Your class MAY implement the description() method.  The description() method returns a description of the functions in your extension.

Your class MAY implement the namespace() method.  The namespace() method returns the namespace (i.e. prefix) for your extension.

Your class MAY implement the copyright() method.  The copyright() method returns the copyright notice for your extension.

Your class MAY implement the label() method.  The label() method returns the short name for your extension.

@function(return_type, description=None, transform=None)

return_type must be one of "bool", "num", "str", "list", "map" or "any".  It describes the return type for your extension function.

description is optional. If provided, it is be visible in the Extension Dialog when the function is selected.

transform is not used yet.

@param(param_type, description=None, optional=False)

All parameters, except self, MUST be described with @param.  Parameter description must be listed in order from left-to-right.

param_type be one of "bool", "num", "str", "list", "map" or "any".  It describes the parameter type for your extension function.

description is optional.  If provided, it is visible in the Extension Dialog when the function is selected.

optional is optional.  It indicates if this parameter is mandatory or if it can be left out.

Tag page
Viewing 1 of 1 comments: view all
What about integrating in Deki google-mobwrite (http://code.google.com/p/google-mobwrite/)?
Concurrent editing is a dream...or no more?
Please, take a look!
Posted 11:41, 30 May 2008
Viewing 1 of 1 comments: view all
You must login to post a comment.
Powered by MindTouch Deki v.8.08.2