eve_resource package

Submodules

eve_resource.events module

eve_resource.exceptions module

exception eve_resource.exceptions.EveResourceError[source]

Bases: Exception

The base exception class.

exception eve_resource.exceptions.NotCallable(func)[source]

Bases: eve_resource.exceptions.EveResourceError, TypeError

Raised if an item is expected to be a callable, but is not.

Return type:None

eve_resource.hooks module

class eve_resource.hooks.EventHooks(resource, EventType=<class 'eve_resource.event.Event'>)[source]

Bases: object

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 of EventType.
  • func (Optional[Callable]) – A callable to register, only used if event is a string, that we use to create an instance of EventType
Return type:

Optional[Callable]

init_api(api)[source]

Register all event’s with an eve.Eve instance.

Parameters:api (Eve) – An eve.Eve instance
Raises:TypeError – If api is not an eve.Eve instance
Return 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]

class eve_resource.hooks.Hooks(resource)[source]

Bases: object

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) – A eve.Eve
Raises:TypeError – If api is not an eve.Eve instance
Return type:None
mongo

A EventHooks setup for mongo type events that can be registered with an eve.Eve api.

request

A EventHooks setup for request type events that can be registered with an eve.Eve api.

eve_resource.hooks.mongo_hooks(resource)[source]

Returns a EventHooks set-up for mongo events.

Return type:EventHooks
eve_resource.hooks.request_hooks(resource)[source]

Returns a EventHooks set-up for request events.

Return type:EventHooks

eve_resource.resource module

class eve_resource.resource.Resource(name, keys=[])[source]

Bases: object

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 instances schema_value will be ignored. If not then when accessing the domain() we will use schema_value as the value for schema in the definition.

domain()[source]

Build’s the domain resource definition for an instance.

Uses the definition_value and schema_value to build a dict that can be used to register an eve.Eve api.

Return type:Dict
hooks

Holds event hooks for that can be registered with an eve.Eve api.

See also

hooks.Hooks

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) – An eve.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 the schema() 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 a dict.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 the domain() method as the value for schema in the domain resource definition, unless a schema is declared in definition_value

eve_resource.utils module

eve_resource.utils.callable_or_error(func)[source]
Return type:Callable
eve_resource.utils.mongo_aliases()[source]

Creates aliases for mongo events.

Return type:Dict
eve_resource.utils.request_aliases()[source]

Creates aliases for request events

Return type:Dict

Module contents

exception eve_resource.NotCallable(func)[source]

Bases: eve_resource.exceptions.EveResourceError, TypeError

Raised if an item is expected to be a callable, but is not.

Return type:None
exception eve_resource.EveResourceError[source]

Bases: Exception

The base exception class.

class eve_resource.EventHooks(resource, EventType=<class 'eve_resource.event.Event'>)[source]

Bases: object

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 of EventType.
  • func (Optional[Callable]) – A callable to register, only used if event is a string, that we use to create an instance of EventType
Return type:

Optional[Callable]

init_api(api)[source]

Register all event’s with an eve.Eve instance.

Parameters:api (Eve) – An eve.Eve instance
Raises:TypeError – If api is not an eve.Eve instance
Return 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]

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
class eve_resource.Hooks(resource)[source]

Bases: object

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) – A eve.Eve
Raises:TypeError – If api is not an eve.Eve instance
Return type:None
mongo

A EventHooks setup for mongo type events that can be registered with an eve.Eve api.

request

A EventHooks setup for request type events that can be registered with an eve.Eve api.

class eve_resource.Event(event, resource, func=None, aliases=None)[source]

Bases: object

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 the resource for this instance and if it does we call the func for this instance.

Parameters:
  • event (str) – A string of the eve.Eve event to register the function for. This can also be a valid value in aliases
  • resource (str) – The eve.Eve domain resource the function is for.
  • func (Optional[Callable]) – A callable that’s called as the event hook.
  • aliases (Optional[Dict]) – A dict with keys being strings of valid convenience aliases a user can use to register an event, the value for the key should be the valid eve.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 not None 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) – The eve.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
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
class eve_resource.Resource(name, keys=[])[source]

Bases: object

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 instances schema_value will be ignored. If not then when accessing the domain() we will use schema_value as the value for schema in the definition.

domain()[source]

Build’s the domain resource definition for an instance.

Uses the definition_value and schema_value to build a dict that can be used to register an eve.Eve api.

Return type:Dict
hooks

Holds event hooks for that can be registered with an eve.Eve api.

See also

hooks.Hooks

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) – An eve.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 the schema() 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 a dict.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 the domain() method as the value for schema in the domain resource definition, unless a schema is declared in definition_value

eve_resource.callable_or_error(func)[source]
Return type:Callable
eve_resource.mongo_aliases()[source]

Creates aliases for mongo events.

Return type:Dict
eve_resource.request_aliases()[source]

Creates aliases for request events

Return type:Dict