Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Extension for spyne so you can easy override services using delegate classes

Project description

Extension for spyne so you can easy override services using delegate classes.

Example usage:

import logging

from wsgiref.simple_server import make_server
from wsgiref.validate import validator

from spyne import Application, Unicode
from spyne import rpc as original_spyne_rpc

from spyne.model.complex import ComplexModel
from spyne.protocol.soap.soap11 import Soap11
from spyne.server.wsgi import WsgiApplication

from spynedelegate.meta import DelegateBase, ExtensibleServiceBase, rpc

logger = logging.getLogger(__name__)

# models
class Chicken(ComplexModel):
    __namespace__ = "spyne.delegate.chicken"
    name = Unicode

class Cow(ComplexModel):
    __namespace__ = "spyne.delegate.cow"
    name = Unicode

# delegates
class ChickenDelegate(DelegateBase):
    @rpc(Chicken, _returns=Chicken.customize(max_occurs='unbounded'))
    def multiplyChickens(self, chicken):  # noqa
        return [chicken, chicken]

class CowDelegate(DelegateBase):
    def method_request_string(self):
        # you can access the context with self.ctx
        return self.ctx.method_request_string

    def gen_name(self, name):
        # and you can use self as well
        return "%s -> %s" % (self.method_request_string, name)

    @rpc(Cow, _returns=Unicode)
    def sayMooh(self, cow):  # noqa
        return self.gen_name(

    @rpc(Cow, _returns=Unicode)
    def noInheritance(self, cow):  # noqa
        # This method won't be inherited because we set the
        # collect_base_methods = False in the overridden delegate
        return self.gen_name(

class CowDelegateOverridden(CowDelegate):

    # With this property we don't expose inherited methods from the base
    # class
    collect_base_methods = False

    @rpc(Cow, _returns=Unicode)
    def sayMooh(self, cow):  # noqa
        # call the super and add a 'overridden' string
        result = super(CowDelegateOverridden, self).sayMooh(cow)
        return "%s overridden" % result

    @rpc(Unicode, _returns=Unicode)
    def generateName(self, name):
        # shows that we call a regular supermethod
        return super(CowDelegateOverridden, self).gen_name(name)

# inheritance
class FarmDelegate(ChickenDelegate, CowDelegateOverridden):

# services
class ChickenService(ExtensibleServiceBase):
    delegate = ChickenDelegate

class FarmService(ExtensibleServiceBase):
    delegate = FarmDelegate

    def thisStillWorks(ctx):  # noqa
        return "Old fashioned spyne"

farm_application = Application(

if __name__ == "__main__":
    wsgi_application = WsgiApplication(farm_application)
    wsgi_server = make_server(
        'localhost', 9876, validator(wsgi_application))'Starting server at %s:%s.' % ('localhost', 9876))'WSDL is at: /?wsdl')


Project details

Release history Release notifications

This version
History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
spyne-delegate-1.0.2.tar.gz (5.5 kB) Copy SHA256 hash SHA256 Source None May 18, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page