Previous topic

Fundamental Data Structures

Next topic

Service Definition

This Page

Application Definition

class spyne.application.Application(services, tns, name=None, in_protocol=None, out_protocol=None, interface=None)[source]

The Application class is the glue between one or more service definitions, input and output protocols.

  • services – An iterable of ServiceBase subclasses that defines the exposed services.
  • tns – The targetNamespace attribute of the exposed service.
  • name – The optional name attribute of the exposed service. The default is the name of the application class which is by default ‘Application’.
  • in_protocol – A ProtocolBase instance that denotes the input protocol. It’s only optional for NullServer transport.
  • out_protocol – A ProtocolBase instance that denotes the output protocol. It’s only optional for NullServer transport.
  • interface – Ignored. Kept for backwards-compatibility purposes.
Supported events:
  • method_call:

    Called right before the service method is executed

  • method_return_object:

    Called right after the service method is executed

  • method_exception_object:

    Called when an exception occurred in a service method, before the exception is serialized.

  • method_context_created:

    Called from the constructor of the MethodContext instance.

  • method_context_closed:

    Called from the close() function of the MethodContext instance, which in turn is called by the transport when the response is fully sent to the client (or in the client case, the response is fully received from server).


This method calls the call_wrapper method in the service definition. This can be overridden to make an application-wide custom exception management.


Takes a MethodContext instance. Returns the response to the request as a native python object. If the function throws an exception, it returns None and sets the exception object to ctx.out_error.

Overriding this method would break event management. So this is not meant to be overridden unless you know what you’re doing.


Call this function first thing in your main function to return original python errors to your clients in case of unhandled exceptions.