API¶
The public interface to EveResource
.
Resource¶
The following items are found in the eve_resource.resource
module.
-
class
eve_resource.
Resource
(name, keys=[])[source] A domain resource for
eve.Eve
api.This class has some conveninence methods for creating a resource as well registering event hooks with the
eve.Eve
api.Parameters: - name – The resource name to be registered with the api.
- keys – Iterable of strings used as a key for the fields of the resource schema.
Example:
persons = Resource('persons', keys=('first_name', 'last_name'))
-
definition
(func)[source] A decorator that uses the return value of the wrapped function to set
definition_value
for an instance.The function should take no args, or kwargs and should return a
dict
. See also:definition_value
.Raises: TypeError – If the return type is not valid for definition_value
Return type: Callable
-
definition_value
The main configuration for an
eve.Eve
domain resource.If a value for
schema
is set inside the definition_value, then this instancesschema_value
will be ignored. If not then when accessing thedomain()
we will useschema_value
as the value forschema
in the definition.See also
-
domain
()[source] Build’s the domain resource definition for an instance.
Uses the
definition_value
andschema_value
to build adict
that can be used to register aneve.Eve
api.Return type: Dict
-
hooks
Holds event hooks for that can be registered with an
eve.Eve
api.See also
-
init_api
(api)[source] Register’s the event hooks with the api and also will register the domain with the api, if one does not exist for the resource.
Parameters: api ( Eve
) – Aneve.Eve
instance.Raises: TypeError – If api is not an eve.Eve
instance.Return type: None
-
key
An optional namedtuple of the fields for the schema fields of an instance.
This get’s created if there are args passed in on instantiation or by calling the
keys()
method. If using theschema()
decorator, then this will get passed into the wrapped function, to be used in building the schema.
-
keys
(*keys)[source] Creates a namedtuple of the keys.
Parameters: keys – Strings that are the fields and values for the namedtuple Return type: None
-
schema
(func)[source] A decorator that uses the return value of the wrapped function to set
schema_value
for an instance.The function can take one arg which will be this instances
key
attribute, will work if the function accepts no args and no kwarrgs as well, and should return adict
.See also:schema_value
.Raises: TypeError – If the return type is not valid for definition_value
Return type: Callable
-
schema_value
The settings for the database and validation portion of the domain resource definition.
This is a
dict
with string keys. This will get added to the definiton when accessing thedomain()
method as the value forschema
in the domain resource definition, unless a schema is declared indefinition_value
See also
Hooks¶
The following items are found in the eve_resource.hooks
module.
-
class
eve_resource.
Hooks
(resource)[source] Container object that holds
EventHooks
for mongo and request events.Parameters: resource ( str
) – The domain resource the hooks are for.Return type: None -
init_api
(api)[source] Register’s the hooks with an
eve.Eve
instance.Parameters: api ( Eve
) – Aeve.Eve
Raises: TypeError – If api
is not aneve.Eve
instanceReturn type: None
-
mongo
A
EventHooks
setup for mongo type events that can be registered with aneve.Eve
api.
-
request
A
EventHooks
setup for request type events that can be registered with aneve.Eve
api.
-
-
class
eve_resource.
EventHooks
(resource, EventType=<class 'eve_resource.event.Event'>)[source] An
Event
container that holds events for a domain resource.Parameters: - resource (
str
) – The domain resource - EventType – The
Event
class or function for the events of this class.
Return type: None
-
event
(event, func=None)[source] Add’s an event to the instance.
Parameters: - event (
Any
) – A string or instance ofEventType
. - func (
Optional
[Callable
]) – A callable to register, only used ifevent
is a string, that we use to create an instance ofEventType
Return type: Optional
[Callable
]- event (
-
init_api
(api)[source] Register all event’s with an
eve.Eve
instance.Parameters: api ( Eve
) – Aneve.Eve
instanceRaises: TypeError – If api is not an eve.Eve
instanceReturn type: None
-
multi_event
(*events, *, func=None)[source] Register’s the same function for multiple events. Can be used as a decorator.
Parameters: - events – Iterable of strings that are the api events to register the function with.
- func (
Optional
[Callable
]) – The function to use for the api hook event.
Return type: Optional
[Callable
]
- resource (
-
eve_resource.
mongo_hooks
(resource)[source]¶ Returns a
EventHooks
set-up for mongo events.Return type: EventHooks
-
eve_resource.
request_hooks
(resource)[source]¶ Returns a
EventHooks
set-up for request events.Return type: EventHooks
Events¶
The following item are found in the eve_resource.events
module.
-
class
eve_resource.
Event
(event, resource, func=None, aliases=None)[source] Holds a function to register with an
eve.Eve
instance as an event hook.This class acts as the function, when the
eve.Eve
event hook is fired, we check that the resource matches theresource
for this instance and if it does we call thefunc
for this instance.Parameters: - event (
str
) – A string of theeve.Eve
event to register the function for. This can also be a valid value inaliases
- resource (
str
) – Theeve.Eve
domain resource the function is for. - func (
Optional
[Callable
]) – A callable that’s called as the event hook. - aliases (
Optional
[Dict
]) – Adict
with keys being strings of valid convenience aliases a user can use to register an event, the value for the key should be the valideve.Eve
event.
Return type: None -
parse_event
(event)[source] Parses an event, returning a valid event that can be registered with an
Eve
instance.Parameters: event ( str
) – A string to check if it’s valid. If no aliases are set for a class, then this will just return the input event.Raises: ValueError – If aliases
is notNone
and the event is not a valid alias.Return type: str
-
register
(app)[source] Register’s an instance with an
eve.Eve
instance.Parameters: app ( Eve
) – Theeve.Eve
instance to register the event with.Return type: None
-
set_func
(func)[source] Set’s the func for an instance, can be used as a decorator.
Parameters: func ( Callable
) – The func to set on the instance.Raises: NotCallable – If the func is not callable. Return type: Callable
- event (
-
eve_resource.
mongo_event
(event, resource, func=None)[source]¶ A function to return an
Event
with aliases set-up for mongo events.The following aliases can be used for mongo events:
+----------+--------------+ | Alias | Eve Event | +==========+==============+ | insert | on_insert | +----------+--------------+ | inserted | on_inserted | +----------+--------------+ | fetch | on_fetch | +----------+--------------+ | fetched | on_fetched | +----------+--------------+ | replace | on_replace | +----------+--------------+ | replaced | on_replaced | +----------+--------------+ | update | on_update | +----------+--------------+ | updated | on_updated | +----------+--------------+ | delete | on_deleted | +----------+--------------+
Return type: Event
-
eve_resource.
request_event
(event, resource, func=None)[source]¶ A function to return an
Event
with aliases set-up for request events.The following aliases can be used for request events:
+--------------+-----------------+ | Alias | Eve Event | +==============+=================+ | pre_GET | on_pre_GET | +--------------+-----------------+ | post_GET | on_post_GET | +--------------+-----------------+ | pre_PUT | on_pre_PUT | +--------------+-----------------+ | post_PUT | on_post_PUT | +--------------+-----------------+ | pre_PATCH | on_pre_PATCH | +--------------+-----------------+ | post_PATCH | on_post_PATCH | +--------------+-----------------+ | pre_POST | on_pre_POST | +--------------+-----------------+ | post_POST | on_post_POST | +--------------+-----------------+ | pre_DELETE | on_pre_DELETE | +--------------+-----------------+ | post_DELETE | on_post_DELETE | +--------------+-----------------+
Return type: Event
Exceptions¶
The following items are found in the eve_resource.exceptions
module.
-
class
eve_resource.
NotCallable
(func)[source] Raised if an item is expected to be a callable, but is not.
Return type: None
-
class
eve_resource.
EveResourceError
[source] The base exception class.
Utils¶
The following items are found in the eve_resource.utils
mdoule.