Skip to main content

Generate full CRUD from mongoengine models

Project description


Python package that generate REST API CRUD from mongoengine models.

The generated API can be used with react-admin since it has the Simple REST Data Provider dialect.


pip install flask-rest-crud


from flask_rest_crud import Crud
from flask_mongoengine import MongoEngine

db = MongoEngine()

class Category(db.Document):
    name = db.StringField(required=True)
    description = db.StringField()

Crud(app, Category, 'categories')


from flask import Flask
from project.crud import Crud
from project.models.category import Category
from flask_mongoengine import MongoEngine
from flask_rest_crud import Crud

db = MongoEngine()

# models
class Category(db.Document):
    name = db.StringField(required=True)
    description = db.StringField()

class Product(db.Document):
    name = db.StringField(required=True)
    description = db.StringField()
    category = db.ReferenceField(Category)

# Create application
app = Flask(__name__)

Crud(app, Category, 'categories', '/api/')
Crud(app, Product, 'products', '/api/')

#  mongodb config
app.config['SECRET_KEY'] = '123456790'
app.config['MONGODB_SETTINGS'] = { 'host': 'hosturi' }

# Create models

app = create_app()

This code will generate the following API endpoints:

Method API calls
getList GET http://my.api.url/api/products?sort=["name","ASC"]&range=[0, 24]&filter={"name":"bar"}
getOne GET http://my.api.url/api/products/123
getMany GET http://my.api.url/api/products?filter={"id":[123,456,789]}
getManyReference GET http://my.api.url/api/products?filter={"category_id":345}
create POST http://my.api.url/api/products
update PUT http://my.api.url/api/products/123
delete DELETE http://my.api.url/api/products/123

Project details

Download files

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

Source Distribution

flask-rest-crud-0.1.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page