Saturday, February 28, 2009

Python actionscript code gen

Tell me if this is familiar
Do you like python .... Of course you do ... if you have used it ... i mean really used it ... there is no way that you haven't fallen in love with it ... I did ... AFTER learning c++ then java then c# then vb then php then actionscript then javascript .... learnt python and loved my life!

Now you have a web project at hand with a shot timeline. So you want to use python. You research and find really nice web frameworks. There's django, pylons, turbogears, cherry py (I love cherrypy!), zope (plone). They are all good but you want something more. You want your user interface to blow the client's mind away! You have heard of RIA and would love if there was someway to integrate with FLEX.

You do a google search and you find pyamf. Looks promising. But you are afraid to use it because of all the actionscript code you are going to have to write interface python with it. Well .... you are a python programmer right. Why not write a python script to generate action script for you!

Well you are in luck... been there ... done that :)

So what was this all about again ?
Enter pyamfcodegen
http://code.google.com/p/pyamfcodegen
Just write you code for the server (using django for session management) and you can use complete object oriented data transfers!

There are just three things you need to do :

  • #s:serviceurl
This goes before your class you want to expose (where serviceurl is like http://localhost/gateway/ and such)
e.g.:
#s:http://localhost:8080/gateway/
class coolservice:

This would mean you want to expose coolserviceat http://localhost:8080/gateway/

  • #f:returntype:parameteronetype,parametertwotype,...


To expose functions e.g.:
#f:bool:String,String
def login(self,username,password):

And finally:
  • #d:propertytype
e.g.:
self.username=username #d:String

HAPPY CODING :)
Code at:
http://code.google.com/p/pyamfcodegen
Frameworks:
http://pyamf.org/
http://www.djangoproject.com/
Screencast :

Python Code Generator from Basarat Ali Syed on Vimeo.

4 comments:

  1. Thank you very much for showing this. Good work!

    ReplyDelete
  2. do you have a sample project including all the python and flex files? the tutorial is great but hard to follow because you talk very fast, and w/out any samples to work with a person cannot just pause and look to see what you are talking about. Very good stuff though!

    ReplyDelete
  3. A good job but with an obscure tutorial for beginners. I gather that the mxmlc shows some warnings indicating that code does not comply with the formality of language. Unfortunately Python support for Flex compared to PHP's garbage. Only workaround.

    ReplyDelete