Previous topic

Service Definition

Next topic

Common Exceptions

This Page

RPC Decorators

The spyne.decorator module contains the the @srpc decorator and its helper methods. The @srpc decorator is responsible for tagging methods as remote procedure calls extracting method’s input and output types.

It’s possible to create custom decorators that wrap the @srpc decorator in order to have a more elegant way of passing frequently-used parameter values. The @rpc decorator is a simple example of this.

spyne.decorator.rpc(*params, **kparams)[source]

Method decorator to tag a method as a remote procedure call in a spyne.service.ServiceBase subclass.

You should use the spyne.server.null.NullServer transport if you want to call the methods directly. You can also use the ‘function’ attribute of the returned object to call the function itself.

_operation_name vs _in_message_name: Soap clients(SoapUI, Savon, suds) will use the operation name as the function name. The name of the input message(_in_message_name) is irrelevant when interfacing in this manner; this is because the clients mostly wrap around it. However, the soap xml request only uses the input message when posting with the soap server; the other protocols only use the input message as well. _operation_name cannot be used with _in_message_name.

Parameters:
  • _returns

    Denotes The return type of the function. It can be a type or a sequence of types for functions that have multiple return

    values.
  • _in_header – A type or an iterable of types that that this method accepts as incoming header.
  • _out_header – A type or an iterable of types that that this method sends as outgoing header.
  • _operation_name – The function’s soap operation name. The operation and SoapAction names will be equal to the value of _operation_name. Default is the function name.
  • _in_message_name – The public name of the function’s input message. Default is: _operation_name + REQUEST_SUFFIX.
  • _out_message_name – The public name of the function’s output message. Default is: _operation_name + RESPONSE_SUFFIX.
  • _in_variable_names – The public names of the function arguments. It’s a dict that maps argument names in the code to public ones.
  • _out_variable_name – The public name of the function response object. It’s a string. Ignored when _body_style != 'wrapped' or _returns is a sequence.
  • _out_variable_names – The public name of the function response object. It’s a sequence of strings. Ignored when _body_style != 'wrapped' or or _returns is not a sequence. Must be the same length as _returns.
  • _body_style – One of ('bare', 'wrapped'). Default: 'wrapped'. In wrapped mode, wraps response objects in an additional class.
  • _soap_body_style – One of (‘rpc’, ‘document’). Default 'document'. _soap_body_style='document' is an alias for _body_style='wrapped'. _soap_body_style='rpc' is an alias for _body_style='bare'.
  • _port_type – Soap port type string.
  • _no_ctx – Don’t pass implicit ctx object to the user method.
  • _no_self – This method does not get an implicit ‘self’ argument (before any other argument, including ctx).
  • _udp – Short for UserDefinedProperties, you can use this to mark the method with arbitrary metadata.
  • _aux – The auxiliary backend to run this method. None if primary.
  • _throws – A sequence of exceptions that this function can throw. This has no real functionality besides publishing this information in interface documents.
  • _args – the name of the arguments to expose.
  • _service_class – A ServiceBase subclass, if you feel like overriding it.
spyne.decorator.srpc(*params, **kparams)[source]

Method decorator to tag a method as a remote procedure call. See spyne.decorator.rpc() for detailed information.

The initial “s” stands for “static”. In Spyne terms, that means no implicit first argument is passed to the user callable, which really means the method is “stateless” rather than static. It’s meant to be used for existing functions that can’t be changed.