Flask-Simon

Simon is a library to help make working with MongoDB easier. Flask-Simon was created to make it even easier to use Simon with your Flask applications.

Installation

To install the latest stable version of Flask-Simon:

$ pip install Flask-Simon

or, if you must:

$ easy_install Flask-Simon

To install the latest development version:

$ git clone git@github.com:dirn/Flask-Simon.git
$ cd Flask-Simon
$ python setup.py install

In addition to Flask-Simon, this will also install:

  • Flask (0.8 or later)
  • PyMongo (2.1 or later)
  • Simon

Quickstart

After installing Flask-Simon, import it where you create your Flask app.

from flask import Flask
from flask.ext.simon import Simon

app = Flask(__name__)
Simon(app)

Simon will establish a connection to the database that will be used as the default database for any Model classes that you define.

Configuration

Simon looks for the following in your Flask app’s configuration:

MONGO_URI A MongoDB URI connection string specifying the database connection.

If the MONGO_URI configuration setting is not present, Simon will connect to localhost and use a database named after the Flask app.

API

class flask_simon.Simon(app=None)

Automatically creates a default connection for Simon models.

init_app(app)

Initializes the Flask app for use with Simon.

This method will automatically be called if the app is passed into __init__().

Parameters:app (flask.Flask) – the Flask application.
flask_simon.get_or_404(model, *qs, **fields)

Finds and returns a single document, or raises a 404 exception.

This method will find a single document within the specified model. If the specified query matches zero or multiple documents, a 404 Not Found exception will be raised.

Parameters:
  • model (simon.Model) – the model class.
  • *qs (simon.query.Q) – logical queries.
  • **fields (kwargs) – keyword arguments specifying the query.

Full details of how to use get_or_404() can be found in the Simon API.

Further Reading

For more information, check out the Simon docs and the MongoDB docs.

Fork me on GitHub