durga package

Submodules

durga.collection module

class durga.collection.Collection(url, resource)[source]

Bases: object

all()[source]
count()[source]
create(data)[source]

Create a new remote resource from a dictionary.

At first the data will be validated. After successful validation the data is converted to JSON. The response of the POST request is returned afterwards.

delete()[source]

Delete all Elements of this Collection.

Return the response for each deleted Element as a list.

elements
filter(**kwargs)[source]
get(**kwargs)[source]
get_element(data)[source]

Return an Element instance holding the passed data dictionary.

get_element_url(id)[source]
get_values(data)[source]

Return either a dictionary, a tuple or a single field.

The data type and the fields returned are defined by using values() or values_list().

order_by()[source]
response = None
update(data)[source]

Update all Elements of this Collection with data from a dictionary.

The data dictionary is used to update the data of all Elements of this Collection. The updated Elements are validated and their data is converted to JSON. A PUT request is made for each Element. Finally a list of all responses is returned.

values(*fields)[source]

Return a list of dictionaries instead of Element instances.

The optional positional arguments, *fields, can be used to limit the fields that are returned.

values_list(*fields, **kwargs)[source]

Return a list of tuples instead of Element instances.

The optional positional arguments, *fields, can be used to limit the fields that are returned.

If only a single field is passed in, the flat parameter can be passed in too. If True, this will mean the returned results are single values, rather than one-tuples.

durga.element module

class durga.element.Element(resource, data)[source]

Bases: object

delete()[source]
get_data()[source]

Return the Element’s data as dictionary.

get_raw()[source]
get_resource()[source]
get_url()[source]
save()[source]

Update the remote resource.

There are two ways to provide data to be saved:

  1. Pass it as a dictionary to the update() method.
  2. Modify the Element’s attributes.

The data will be validated before the PUT request is made. After a successful update an updated Element instance is returned.

update(data)[source]

Update the attributes with items from the data dictionary.

validate()[source]

Validate the Element’s data.

If validation fails a schema.SchemaError is raised.

durga.exceptions module

exception durga.exceptions.DurgaError[source]

Bases: Exception

Main exception class.

exception durga.exceptions.MultipleObjectsReturnedError[source]

Bases: durga.exceptions.DurgaError

The request returned multiple objects when only one was expected.

That is, if a GET request returns more than one element.

exception durga.exceptions.ObjectNotFoundError[source]

Bases: durga.exceptions.DurgaError

The requested object does not exist.

exception durga.exceptions.ValidationError[source]

Bases: durga.exceptions.DurgaError

The value did not pass the validator.

durga.resource module

class durga.resource.Resource[source]

Bases: object

collection
dispatch(request)[source]

Dispatch the Request instance and return an Response instance.

extract(response)[source]

Return a list of JSON data extracted from the response.

headers = {}
id_attribute

Element attribute name to be used as primary id.

object_path = ()
objects_path = ()
schema = None
url

Full URL of the resource.

validate(data)[source]

Validate the passed data.

If data is empty or no schema is defined the data is not validated and returned as it is.

durga.validators module

durga.validators.email(value)[source]

Check if value is a valid email address.

durga.validators.url(value)[source]

Check if value is a valid URL.

durga.validators.uuid4(value)[source]

Check if value is a valid UUID version 4.