Python SOAP server (flask) + wsdl generation

Simple tutorial how quickly create SOAP server using python “Flask-Enterprise” package for “flash” web framework. Example comes with basic client using “suds” package.

Install

    $ pip install Flask-Enterprise

file: soap.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    from time import ctime
    from flask import Flask
    from flaskext.enterprise import Enterprise

    app = Flask(__name__)

    enterprise = Enterprise(app)


    class DemoService(enterprise.SOAPService):
        __soap_server_address__ = '/soap'
        __soap_target_namespace__ = 'ns'

        @enterprise.soap(_returns=enterprise._sp.String)
        def get_time(self):
            return ctime()

    if __name__ == '__main__':
        app.run(host='127.0.0.1', port=5555)

Run service

    $ python soap.py

file: client.py

1
2
3
4
    from suds.client import Client

    c = Client('http://127.0.0.1:5555/soap?wsdl')
    print c.service.get_time()

Run test

    $ python client.py
    Tue Aug 13 19:49:53 2013