pypykim / flask-spyne

Flask extenstion which provides Spyne support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask-Spyne

Flask-Spyne is a Flask extension which provides Spyne (formerly known as soaplib) support. Includes SOAP, WSDL, JSON, XML, YAML and other transports and protocols. Inspired by unofficial Flask-Enterprise extension (a wrapper on top of outdated soaplib).

Installation

pip install flask-spyne

Please check list of additional requirements you might need to install.

Server example

from flask import Flask
from flask.ext.spyne import Spyne
from spyne.protocol.soap import Soap11
from spyne.model.primitive import Unicode, Integer
from spyne.model.complex import Iterable

app = Flask(__name__)
spyne = Spyne(app)

class SomeSoapService(spyne.Service):
    __service_url_path__ = '/soap/someservice'
    __in_protocol__ = Soap11(validator='lxml')
    __out_protocol__ = Soap11()

    @spyne.srpc(Unicode, Integer, _returns=Iterable(Unicode))
    def echo(str, cnt):
        for i in range(cnt):
            yield str

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

Client example

from suds.client import Client as SudsClient

url = 'http://127.0.0.1:5000/soap/someservice?wsdl'
client = SudsClient(url=url, cache=None)
r = client.service.echo(str='hello world', cnt=3)
print r

WS-Security

Starting from v0.2 flask-spyne supports basics of WS-Security for SOAP services.

Specify __wsse_conf__ dict with following fields:

username (str, required)
password (str, required)
password-digest (bool, optional)
nonce-freshness-time (int, optional)
reject-empty-nonce-creation (bool, optional)
reject-stale-tokens (bool, optional)
reject-expiry-limit (int, optional)

See server_auth.py/client_auth.py in examples for more details.

About

Flask extenstion which provides Spyne support

License:BSD 2-Clause "Simplified" License


Languages

Language:Python 100.0%