API

Collection

class mongorest.collection.Collection(document=None)[source]

Base Class for Collections.

after_delete()[source]

Callback called after a delete occurs.

after_insert()[source]

Callback called after an insert occurs.

after_update(old)[source]

Callback called after an update occurs.

after_validation()[source]

Callback called after the validation of a document occurs. Should return None to allow the next callbacks to run. If anything else is returned the next callbacks are not called and __init__ is finished

after_validation_failed()[source]

Callback called after the validation of a document fails.

after_validation_succeeded()[source]

Callback called after the validation of a document succeeds.

classmethod aggregate(*args, **kwargs)[source]

Returns the document dicts returned from the Aggregation Pipeline

before_delete()[source]

Callback called before a delete occurs. Should return None to allow the delete to happen. If anything else is returned the delete will not occur and the returned value will be the return of the delete function

before_insert()[source]

Callback called before an insert occurs. Should return None to allow the insert to happen. If anything else is returned the insert will not occur and the returned value will be the return of the insert function

before_update(old)[source]

Callback called before an update occurs. Should return None to allow the update to happen. If anything else is returned the update will not occur and the returned value will be the return of the update function

before_validation()[source]

Callback called before the validation of a document occurs. Should return None to allow the validation process to happen. If anything else is returned the validation is not executed and __init__ is finished

classmethod count(*args, **kwargs)[source]

Returns the number of documents that pass the filter

delete(*args, **kwargs)[source]

Deletes the document if it is saved in the collection.

classmethod delete_many(*args, **kwargs)[source]

Deletes all documents that pass the filter

classmethod delete_one(*args, **kwargs)[source]

Deletes one document that passes the filter

document

Returns the document

classmethod documents(filter=None, **kwargs)[source]

Returns a list of Documents if any document is filtered

errors

Returns the validation errors

classmethod find(*args, **kwargs)[source]

Returns all document dicts that pass the filter

classmethod find_one(*args, **kwargs)[source]

Returns one document dict if one passes the filter. Returns None otherwise.

classmethod get(filter=None, **kwargs)[source]

Returns a Document if any document is filtered, returns None otherwise

insert(*args, **kwargs)[source]

Saves the Document to the database if it is valid. Returns errors otherwise.

classmethod insert_many(*args, **kwargs)[source]

Inserts a list of documents into the Collection and returns their _ids

classmethod insert_one(*args, **kwargs)[source]

Inserts a document into the Collection and returns its _id

is_valid

Returns True if no validation errors have been found, False otherwise.

classmethod replace_one(*args, **kwargs)[source]

Replaces a document that passes the filter. Will upsert a new document if upsert=True and no document is filtered

update(*args, **kwargs)[source]

Updates the document with the given _id saved in the collection if it is valid. Returns errors otherwise.

classmethod update_many(*args, **kwargs)[source]

Updates all documents that pass the filter with the update value Will upsert a new document if upsert=True and no document is filtered

classmethod update_one(*args, **kwargs)[source]

Updates a document that passes the filter with the update value Will upsert a new document if upsert=True and no document is filtered

Decorators

mongorest.decorators.login_required(wrapped)[source]

Requires that the user is logged in and authorized to execute requests Except if the method is in authorized_methods of the auth_collection Then he can execute the requests even not being authorized

mongorest.decorators.serializable(wrapped)[source]

If a keyword argument ‘serialize’ with a True value is passed to the Wrapped function, the return of the wrapped function will be serialized. Nothing happens if the argument is not passed or the value is not True

Middlewares

class mongorest.middlewares.AuthenticationMiddleware(app)[source]

Authentication Middleware works with Cookie and Token Authentication

class mongorest.middlewares.CORSMiddleware(app)[source]

CORS Middleware used to overcome CORS restrictions

Resources

Resource

class mongorest.resource.Resource[source]

Just a class that puts together te WSGIWrapper and the ResourceMeta To be used as base for any resource to be created.

collection

alias of Collection

ListResourceMixin

class mongorest.resource.ListResourceMixin[source]

Resource Mixin that provides the list action for your endpoint.

list(request)[source]

Returns the list of documents found on the collection

CreateResourceMixin

class mongorest.resource.CreateResourceMixin[source]

Resource Mixin that provides the create action for your endpoint.

create(request)[source]

Creates a new document based on the given data

RetrieveResourceMixin

class mongorest.resource.RetrieveResourceMixin[source]

Resource Mixin that provides the retrieve action for your endpoint.

retrieve(request, _id)[source]

Returns the document containing the given _id or 404

UpdateResourceMixin

class mongorest.resource.UpdateResourceMixin[source]

Resource Mixin that provides the update action for your endpoint.

update(request, _id)[source]

Updates the document with the given _id using the given data

DeleteResourceMixin

class mongorest.resource.DeleteResourceMixin[source]

Resource Mixin that provides the delete action for your endpoint.

delete(request, _id)[source]

Deletes the document with the given _id if it exists

Utils

mongorest.utils.deserialize(to_deserialize, *args, **kwargs)[source]

Deserializes a string into a PyMongo BSON

mongorest.utils.serialize(to_serialize, *args, **kwargs)[source]

Serializes a PyMongo BSON into a string

Wrappers

Request

class mongorest.wrappers.Request(environ, populate_request=True, shallow=False)[source]

Wrapper around Werkzeug Request object, provides easier access to data

Response

class mongorest.wrappers.Response(response=None, status=None, headers=None, mimetype=None, content_type=None, direct_passthrough=False)[source]

Wrapper around Werkzeug Response object, provides easier access to data

WSGI

WSGIWrapper

class mongorest.wsgi.WSGIWrapper[source]

Wrapper for WSGI Elements. This class is the base for Class Based Views. For example the ones created on resource.py It knows how to route its requests to the correct views using the url_map

WSGIDispatcher

class mongorest.wsgi.WSGIWrapper[source]

Wrapper for WSGI Elements. This class is the base for Class Based Views. For example the ones created on resource.py It knows how to route its requests to the correct views using the url_map