Skip to main content
Flask Stack PyMongo

This is a short guide on how to integrated MongoDB Atlas to Flask applications using Flask-PyMongo wrapper and pymongo driver.

Hannah Geiser avatar
Written by Hannah Geiser
Updated over a year ago

Introduction

Implementation of flask and PyMongo using mflix sample data set and mflix python UI. This is a short guide on how to integrated MongoDB Atlas to Flask applications using Flask-PyMongo wrapper and PyMongo driver.

Project Structure

The mflix directory holds the application logic.

  • db.py Where all database CRUD patterns are exposed as functions.

  • api/movies.py Where the web api is exposed to the UI

The main directory holds the following files:

  • run.py Where the Flask application is initialize and the config is loaded

  • sample_ini Where the connection URI to MongoDB Atlas is configured

  • requirments.txt Where the dependencies this project needs to run are located.

How to set up

Clone the repository:

git clone git@github.com:mongodb-developer/flask-pymongo-example.git

Start a python virtual env:

# navigate to the flask-pymongo-example directory
cd flask-pymongo-example

# create the virtual environment for MFlix
python3 -m venv mflix-venv

# activate the virtual environment
source mflix_venv/bin/activate

Install dependencies

python3 -m pip install -r requirments.txt

Rename the sample_ini to .ini.

Place your connection string in DB_URI parameter under .ini

Start the application

python ./run.py

Open your browser on http://localhost:5000

Did this answer your question?