Home

Nov. 4, 2015, 2 min read

sandman makes things REST

Imagine you have an existing database and want to be able to modify it with a tool through a nifty REST API, while still being able to edit it manually without hassle. I guess we need to create a web backend and frontend, write models for our data and view functions to allow a mapping of their attributes to URLs to access and change them with http requests.. so much work! Not with sandman:

$ pip install sandman
$ sandmanctl <database-uri>
for example:

$ sandmanctl mysql://username:password@host/database --host localsandman --port 8080
It will analyze your database, derive models from it, create REST API functions for them, map those to URLs that make sense and run a small server exposing everything on your chosen port, e.g. http://localsandman:8080/. It will also create an admin page as the web GUI to your database on http://localsandman:8080/admin/. How cool is that ? All powered by flask and SQLAlchemy. Note: It seems sandman is not maintained anymore, but a successor is in the making: sandman2, however I could not get it to run on my machine yet. I also had two issues installing sandman on Windows 7 with Python 2.7, so I will quickly list the fixes here:

$ git clone https://github.com/jeffknupp/sandman
$ python setup.py install
  • When trying to connect to a mysql database, the underlying SQLAlchemy defaults to the MySQLdb (available on pypi as MySQL-python) module, which on Windows can be a pain to install since it needs a compiler, which usually is not available. You can tell it to use a pure-python alternative named pymysql by modifying the URI like:
  • 
    $ pip install pymysql
    $ sandmanctl mysql+pymysql://username:password@host/database --host localsandman --port 8080