Fernando Correia’s Weblog

July 16, 2008

Inserting and retrieving objects using PyAMF with GAE

Filed under: Software Development — Fernando Correia @ 9:50 pm
Tags: ,

I advanced another step on my Flex and Python Test project. Now it is able to insert new objects in the data store and to retrieve them.

The Python client has some new abilities:

client.py test

Runs an Echo test against the server. This is the result:


client.py insert code name

This command inserts new objects on the data store. For instance:

client.py insert 10 "Project Ten"
client.py insert 12 "Project Twelve"

client.py get code

This command gets an object by one of its fields (code). For instance:

client.py get 10

Results in:

Project code = 10, name = Project Ten, created at 2008-07-17 00:20:32

The data is returned as an object.

client.py all

Retrieves all objects as a list:

Project code = 10, name = Project Ten, created at 2008-07-17 00:20:32
Project code = 12, name = Project Twelve, created at 2008-07-17 00:20:55

Some code highlights:

in server/services/ProjectService.py:

class ProjectService:
    def get(self, code):
        project = Project.gql("WHERE code = :1", code).get()
        return project
    def insert(self, code, name):
        project = Project()
        project.code = code
        project.name = name

    def get_all(self):
        return Project.all().fetch(1000)

in python-client/client.py:

def insert(code, name):
    gw = RemotingService('http://localhost:8080/')
    service = gw.getService('ProjectService')
    service.insert(int(code), name)

def get(code):
    gw = RemotingService('http://localhost:8080/')
    service = gw.getService('ProjectService')
    project = service.get(int(code))
    if project == None:
        print "Project %s not found." % (code)

def all():
    gw = RemotingService('http://localhost:8080/')
    service = gw.getService('ProjectService')
    projects = service.get_all()
    for project in projects:

My next step will be to add these abilities to the Flex client as well.

The project is hosted in github. Comments are most welcome.


1 Comment »

  1. […] Inserting and retrieving objects using PyAMF with GAE […]

    Pingback by Example of RIA in the cloud « Fernando Correia’s Weblog — October 4, 2008 @ 9:47 am

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: