Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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')

Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
spyne-delegate-1.0.2.tar.gz (5.5 kB) Copy SHA256 Checksum SHA256 Source May 18, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting