Skip to main content

SQLAlchemy backup/dump tool for Flask

Project description


Do you use Flask with SQLAlchemy and Flask-Script ? Wow, what a coincidence!

This package let you backup and restore all your data using SQLALchemy dumps() method.

It is an easy way (one singe command, I mean it) to save all the data stored in your database.


Considering you have these models (SQLAlchemy mapped classes):

class User(Model):
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(140), index=True, unique=True)

class Post(Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(140))
    content = db.Column(db.UnicodeText)

You can backup all your data:

$ python alchemydumps create


==> 3 rows from User post saved as /vagrant/alchemydumps/db-bkp-20141115172107-User.gz
==> 42 rows from Post saved as /vagrant/alchemydumps/db-bkp-20141115172107-Post.gz

You can list the backups you have already created:

$ python alchemydumps history


==> ID: 20141114203949 (from Nov 15, 2014 at 17:21:07)

==> ID: 20141115140629 (from Nov 15, 2014 at 14:06:29)

And, surely, you can restore backuped data:

$ python alchemydumps restore -d 20141115172107


==> /vagrant/alchemydumps/db-bkp-20141115172107-User.gz totally restored.
==> /vagrant/alchemydumps/db-bkp-20141115172107-Post.gz totally restored.


First install the package: $ pip install flask-alchemydumps

Then configure it in your Flask application:

from alchemydumps import AlchemyDumps, AlchemyDumpsCommand
from flask import Flask
from flask.ext.script import Manager
from flask.ext.sqlalchemy import SQLAlchemy

app = Flask(__name__)
db = SQLAlchemy(app)
manager = Manager(app)

alchemydumps = AlchemyDumps(app, db)
manager.add_command('alchemydumps', AlchemyDumpsCommand)

The first line import the methods from the package, the last two lines instantiate and add AlchemyDumps to the Flask-Script manager).

You might want to add alchemydumps to yout .gitignore. It is the folder where AlchemyDumps save the backup files.


As AlchemyDumps was designed to work together with Flask applications that uses SQLAlchemy. And it runs within the Flask-Script manager. Thus, be sure to have these packages installed and in use. AlchemyDumps also uses Unipath package.

In sum, if your requirements.txt looks something like this, probably you will be fine:



Copyright (c) 2014 Eduardo Cuducos.

Licensed under the MIT License.

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-AlchemyDumps-0.0.1.tar.gz (4.8 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