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.Eveapi.This class has some conveninence methods for creating a resource as well registering event hooks with the
eve.Eveapi.Parameters: - name – The resource name to be registered with the api.
- keys – Strings used as a key for the fields of the resource schema.
Example:
persons = Resource('persons', 'first_name', 'last_name')
-
definition(func)[source] A decorator that uses the return value of the wrapped function to set
definition_valuefor 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_valueReturn type: Callable
-
definition_value The main configuration for an
eve.Evedomain resource.If a value for
schemais set inside the definition_value, then this instancesschema_valuewill be ignored. If not then when accessing thedomain()we will useschema_valueas the value forschemain the definition.See also
-
domain()[source] Build’s the domain resource definition for an instance.
Uses the
definition_valueandschema_valueto build adictthat can be used to register aneve.Eveapi.Return type: Dict
-
hooks Holds event hooks for that can be registered with an
eve.Eveapi.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.Eveinstance.Raises: TypeError – If api is not an eve.Eveinstance.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_valuefor an instance.The function can take one arg which will be this instances
keyattribute, 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_valueReturn type: Callable
-
schema_value The settings for the database and validation portion of the domain resource definition.
This is a
dictwith string keys. This will get added to the definiton when accessing thedomain()method as the value forschemain the domain resource definition, unless a schema is declared indefinition_valueSee also
Hooks¶
The following items are found in the eve_resource.hooks module.
-
class
eve_resource.Hooks(resource)[source] Container object that holds
EventHooksfor 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.Eveinstance.Parameters: api ( Eve) – Aeve.EveRaises: TypeError – If apiis not aneve.EveinstanceReturn type: None
-
mongo A
EventHookssetup for mongo type events that can be registered with aneve.Eveapi.
-
request A
EventHookssetup for request type events that can be registered with aneve.Eveapi.
-
-
class
eve_resource.EventHooks(resource, EventType=<class 'eve_resource.event.Event'>)[source] An
Eventcontainer that holds events for a domain resource.Parameters: - resource (
str) – The domain resource - EventType – The
Eventclass 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 ifeventis 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.Eveinstance.Parameters: api ( Eve) – Aneve.EveinstanceRaises: TypeError – If api is not an eve.EveinstanceReturn 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
EventHooksset-up for mongo events.Return type: EventHooks
-
eve_resource.request_hooks(resource)[source]¶ Returns a
EventHooksset-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.Eveinstance as an event hook.This class acts as the function, when the
eve.Eveevent hook is fired, we check that the resource matches theresourcefor this instance and if it does we call thefuncfor this instance.Parameters: - event (
str) – A string of theeve.Eveevent to register the function for. This can also be a valid value inaliases - resource (
str) – Theeve.Evedomain resource the function is for. - func (
Optional[Callable]) – A callable that’s called as the event hook. - aliases (
Optional[Dict]) – Adictwith keys being strings of valid convenience aliases a user can use to register an event, the value for the key should be the valideve.Eveevent.
Return type: None -
parse_event(event)[source] Parses an event, returning a valid event that can be registered with an
Eveinstance.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 aliasesis notNoneand the event is not a valid alias.Return type: str
-
register(app)[source] Register’s an instance with an
eve.Eveinstance.Parameters: app ( Eve) – Theeve.Eveinstance 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
Eventwith 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
Eventwith 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.