Skip to main content

Flask-RESTive extension to work with MongoDB.

Project description

# flask-restive-mongodb
Flask-RESTive extension to work with mongodb.

[![Build Status](](
[![Coverage Status](](
[![Code Health](](
[![PyPI Version](](

## Installation

pip install flask-restive-mongodb

## How to use

from datetime import datetime

import mongoengine as me
from flask import Flask
from flask_restive import Api, StorageResource, UUIDSchema, fields
from marshmallow import pre_load
from flask_restive_mongodb import Model, Storage

app = Flask(__name__)

app.config['MONGODB_DATABASE_URI'] = 'mongodb://localhost/local'

def utc_time():
return datetime.utcnow().replace(microsecond=0)

class ClientSchema(UUIDSchema):
first_name = fields.String(required=True)
last_name = fields.String(required=True)
created_on = fields.DateTime(
missing=lambda: utc_time().isoformat())
updated_on = fields.DateTime()

class Meta(UUIDSchema.Meta):
sortable_fields = ('id', 'created_on', 'updated_on')
default_sorting = ('-updated_on', '-created_on', 'id')

def set_updated_on(self, data):
# update time stamp on each create/update operation
data['updated_on'] = utc_time().isoformat()
return data

class ClientModel(Model):
id = me.fields.UUIDField(primary_key=True)
first_name = me.fields.StringField()
last_name = me.fields.StringField()
created_on = me.fields.DateTimeField()
updated_on = me.fields.DateTimeField()

class ClientStorage(Storage):

class Meta(Storage.Meta):
model_cls = ClientModel
primary_key_fields = ('id',)

class ClientResource(StorageResource):
data_schema_cls = ClientSchema
storage_cls = ClientStorage

api = Api(app, prefix='/api/v1', api_resources=[
(ClientResource, ('/clients', '/clients/<uuid:id>')),

if __name__ == '__main__':'', port=5000)


Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
Flask_RESTive_MongoDB-0.0.1-py3-none-any.whl (8.2 kB) Copy SHA256 hash SHA256 Wheel py3 Sep 18, 2017
Flask-RESTive-MongoDB-0.0.1.tar.gz (5.1 kB) Copy SHA256 hash SHA256 Source None Sep 18, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page