How develop and deploy an application in the cloud. A referencial architecture (Part 1)

February 10th, 2014


See how we can implement an Architecture using the cloud services, Openshift Django / Python and Redis in the Cloud.

Python and MongoLab (Mongo in the Cloud)

January 19th, 2014

This is a little tutorial how use MongoDB on the Cloud.

First we need find Mongo in the cloud...I will use MongoLab for demonstrate how work pymongo.

We need to create a account on and complete the form

Follow the instructions to create a database and create a user on MongoLab web console.

To connect using a driver via the standard URI:


When you create a database on MongoLab a port is assigned to the resource.

For our example, we create a database called db_posts.

Assume that port 28012 is created


Important: you must create the dbuser (, this is not the user account.

Well, now we go to write the python code.

Create the file to insert a document into the collection:

1  from pymongo import MongoClient
3  client = MongoClient('')
4  client.db.authenticate('joe','pass12345',source='db_posts')
6  db = client.db_posts
7  posts = db.posts
8  post = {'author':'rodrigo','text':'Hello world'}
10 id_post = posts.insert(post)
11 print 'Create the id : %s'%id_post
13 client.close()

Create the file to retrieve documents from the collection:

1  from pymongo import MongoClient
3  client = MongoClient('')
4  client.db.authenticate('joe','pass12345',source='db_posts')
6  db = client.db_posts
8  results_posts = db.posts.find()
9  for post in results_posts:
10     print post
12 client.close()

I hope with this you can see how work python and mongo in the cloud, If you like MongoHQ, that is similar to use MongoLab.


The Classic Hello World!!!

January 4th, 2012

We will develop the classic hello world!!! like a SOAP web service.

The purpose of this example is to explain how tornado-webservices works, with the use of the classic Hello World.

Note: For this example you must to use tornadows-

Step 1: Create a file named

1  import tornado.httpserver
2 import tornado.ioloop
3 from tornadows import soaphandler
4 from tornadows import webservices
5 from tornadows.soaphandler import webservice
7 class HelloWorldService(soaphandler.SoapHandler):
8 @webservice(_params=None,_returns=str)
9 def sayHello(self):
10 return 'Hello World!!!'
12 if __name__ == '__main__':
13 service = [('HelloService',HelloWorldService)]
14 app = webservices.WebService(service)
15 ws = tornado.httpserver.HTTPServer(app)
16 ws.listen(8080)
17 tornado.ioloop.IOLoop.instance().start()

First, the class HelloWorldService (lines 7 to 10) is the service that holds the operation or methods that contains the logical of the service.

With the decorator @webservice, indicates that the method sayHello () (lines 8 to 10) is the operation of the service.

In the line 13, service = [('HelloService','HelloWorldService')], indicates the name of the service that will be published on the net.

The tuple ('HelloWorld','HelloWorldService') associates the name of the service with the class of python. By this way the service can be accesed like:


Finally, in  the line 16, indicates that we are listening from the port 8080.

Step 2: Running the service.

Simply execute:

$ python

Step 3: Testing with a client.

Now, I will created a client to HelloService with suds (0.3.7).

Create a file named with this code:

1  import suds
3 url = 'http://localhost:8080/HelloService?wsdl'
4 client = suds.client.Client(url,cache=None)
5 print client.service.sayHello()

Note that we don't pass any parameters to the operation sayHello().

line 1: we import the api python-suds.

line3: indicates the url with the Web Service Description Language (WSDL), in other words, the location of web service.

line 4: is created the client of the web service.

line 5: finally, is printed the result. The result should be (of course): "Hello World!!!"

For running the client, simply execute:

$ python

Hello World!!!

You can see more examples in:

And documentation in:

You can download directly from:

For check prerequisites and install see:


Python classes to XML/XSD

September 11th, 2011

If you want to test a python module that transforms python classes to XML and XSD documents look at:

Web Services and ComplexTypes

August 13th, 2011

It incorporates the mechanism for the use of python classes like xml complex types.

You must downloads and install the new release:

(Don't forget, you need have installed tornado web server).

In the example, the web service allows the consultation of products stored in a database.

Create the file

import tornado.httpserver
import tornado.ioloop
from tornadows import soaphandler
from tornadows import webservices
from tornadows import complextypes
from tornadows.soaphandler import webservice

class Input(complextypes.ComplexType):
idProduct = complextypes.IntegerProperty()

class Product(complextypes.ComplexType):
id = complextypes.IntegerProperty()
name = complextypes.StringProperty()
price = complextypes.FloatProperty()
stock = complextypes.IntegerProperty()

class ProductService(soaphandler.SoapHandler):
def getProduct(self, input):
id = input.idProduct.value

reg = self.database(id)

output = Product() = id = reg[0]
output.price.value = reg[1]
output.stock.value = reg[2]

return output

def database(self,id):
""" This method simulates a database of products """
db = {1:('COMPUTER',1000.5,100),
3:('PENCIL BLUE',0.50,500),
4:('PENCIL RED',0.50,600),
5:('PENCIL WHITE',0.50,900),
row = (None,0.0,0)
row = db[id]
return row

if __name__ == '__main__':
service = [('ProductService',ProductService)]
app = webservices.WebService(service)
ws = tornado.httpserver.HTTPServer(app)

Executing the service with.

$ python

You can see the WSDL from http://localhost:8080/ProductService?wsdl

For testing the service, you can use SoapUI or use python-suds.

You can use the next code:

import suds

url = 'http://localhost:8080/ProductService?wsdl'
client = suds.client.Client(url)

print client
# Param IdProduct, you can test with 1,2,3...
idProduct = 1
output = client.factory.create('Product')
output = client.service.getProduct(idProduct)

print 'Result'
print '---------------------------------'
print 'Id.Product : %d'
print 'Name Product : %s'
print 'Price : %f'%output.price
print 'Stock : %d'%output.stock
print '---------------------------------'

You need have installed python-suds, you can download it from:

Now, you can running the script for test the service.