API¶
Public API¶
wsme
– Essentials¶
-
class
wsme.
signature
([return_type, [arg0_type, [arg1_type, ..., ]]]body=None, status_code=None)[source]¶ Decorator that specify the argument types of an exposed function.
Parameters: - return_type – Type of the value returned by the function
- argN – Type of the Nth argument
- body – If the function takes a final argument that is supposed to be the request body by itself, its type.
- status_code – HTTP return status code of the function.
- ignore_extra_args – Allow extra/unknow arguments (default to False)
Most of the time this decorator is not supposed to be used directly, unless you are not using WSME on top of another framework.
If an adapter is used, it will provide either a specialised version of this decororator, either a new decorator named @wsexpose that takes the same parameters (it will in addition expose the function, hence its name).
-
class
wsme.
wsattr
(datatype, mandatory=False, name=None, default=Unset, readonly=False)[source]¶ Complex type attribute definition.
Example:
class MyComplexType(wsme.types.Base): optionalvalue = int mandatoryvalue = wsattr(int, mandatory=True) named_value = wsattr(int, name='named.value')
After inspection, the non-wsattr attributes will be replaced, and the above class will be equivalent to:
class MyComplexType(wsme.types.Base): optionalvalue = wsattr(int) mandatoryvalue = wsattr(int, mandatory=True)
-
class
wsme.
wsproperty
(datatype, fget, fset=None, mandatory=False, doc=None, name=None)[source]¶ A specialised
property
to define typed-property on complex types. Example:class MyComplexType(wsme.types.Base): def get_aint(self): return self._aint def set_aint(self, value): assert avalue < 10 # Dummy input validation self._aint = value aint = wsproperty(int, get_aint, set_aint, mandatory=True)
-
wsme.
Unset
¶ Default value of the complex type attributes.
-
class
wsme.
WSRoot
(protocols=[], webpath='', transaction=None, scan_api=<function scan_api>)[source]¶ Root controller for webservices.
Parameters: - protocols – A list of protocols to enable (see
addprotocol()
) - webpath – The web path where the webservice is published.
- transaction (A transaction-like
object or
True
.) –If specified, a transaction will be created and handled on a per-call base.
This option can be enabled along with repoze.tm2 (it will only make it void).
If
True
, the defaulttransaction
module will be imported and used.
- protocols – A list of protocols to enable (see
Internals¶
wsme.types
– Types¶
wsme.api
– API related api¶
-
class
wsme.api.
FunctionArgument
(name, datatype, mandatory, default)[source]¶ An argument definition of an api entry
-
name
= None¶ argument name
-
datatype
= None¶ Data type
-
mandatory
= None¶ True if the argument is mandatory
-
default
= None¶ Default value if argument is omitted
-
-
class
wsme.api.
FunctionDefinition
(func)[source]¶ An api entry definition
-
name
= None¶ Function name
-
doc
= None¶ Function documentation
-
return_type
= None¶ Return type
-
arguments
= None¶ The function arguments (list of
FunctionArgument
)
-
body_type
= None¶ If the body carry the datas of a single argument, its type
-
status_code
= None¶ Status code
-
ignore_extra_args
= None¶ True if extra arguments should be ignored, NOT inserted in the kwargs of the function and not raise UnknownArgument exceptions
-
pass_request
= None¶ name of the function argument to pass the host request object. Should be set by using the
wsme.types.HostRequest
type in the function @:function:`signature`
-
extra_options
= None¶ Dictionnary of protocol-specific options.
-
static
get
(func)[source]¶ Returns the
FunctionDefinition
of a method.
-
get_arg
(name)[source]¶ Returns a
FunctionArgument
from its name
-