Package: sandman2
sandman2 documentationsandman2automagically generates a RESTful API service from your
existing database, without requiring you to write a line of code. Simply
pointsandman2to your database, add salt for seasoning, and voila!,
a fully RESTful API service with hypermedia support starts running,
ready to accept HTTP requests.This is a big deal. It means every single database you interact with,
from the SQLite database that houses your web browser’s data up to your
production PostgreSQL server can be endowed with a REST API and accessed
programatically, using any number of HTTP client libraries available ineverylanguage.sandman2frees your data.For developers:Imagine you’re working for AnonymousCorp and need to access Group Y’s
data, which is presented to you through some horrible API or GUI.
Wouldn’t it be nice if you could just interact with that database
through a REST API?More than that, imagine if you could interact with the database through
a REST APIand no one had to write any code. Not you. Not Group Y.
No one. That means no boilerplate ORM code, no database connection
logic. Nothing.sandman2can be run as a command-line tool
(sandman2ctl) that just takes your database information as
parameters and connects to it, introspects the schema, generates a
RESTful API, and starts the server.What Happened to Sandman (1)?`sandman<http://www.github.com/jeffknupp/sandman>`__, the precursor
tosandman2, is no longer being maintained.sandmanhad almost
identical functionality but had an architecture that reflected the
capabilities of the underlying ORM, SQLAlchemy. As of the0.9release, SQLAlchemy introduced theautomapconstruct. This
fundamentally changed the way thatsandmancouldinteract with the
underlying database in a way that greatly simplified things. All that
was needed was the actual effort to rewritesandmanfrom scratch…After wrestling with the idea for a while, I finally gave in and started
the rewrite project.sandman2is that project. While I’ll continue
to supportsandmanin the nearterm,sandman2definitely
represents the way forward.NOTE:sandman2is not yet at feature parity with the originalsandman, but should be soon. Getting there is currently the top
priority.QuickstartInstallsandman2usingpip:$ pip install sandman2. This
provides the scriptsandman2ctl, which just takes the database URI
string, describedhere. For
example, to connect to a SQLite database in the same directory you’re
running the script, you would run:$sandman2ctlsqlite+pysqlite:///database_file_nameTo connect to a PostgreSQL database, make sure you install a driver likepsycopg2usingpip, then use the following connection string:$sandman2ctlpostgresql+psycopg2://scott:tiger@localhost/mydatabaseAgain, seethe SQLAlchemy
documentationfor a more comprehensive discussion of connection strings.Supported Databasessandman2supports all databases that the underlying ORM, SQLAlchemy,
supports. Presently, that includes:MySQLPostgreSQLOracleMicrosoft SQL ServerSQLiteSybaseDrizzleFirebirdThird-party packages extend support to:IBM DB2Amazon RedshiftSQL AnywhereMonetDBAdmin InterfaceOne of the best things about the original`sandman<http://www.github.com/jeffknupp/sandman>`__ was theAdmin
Interface. Not only doessandman2include the Admin Interface, but
it modernizes it as well. The layout has been greatly improved,
especially when dealing with larger numbers of tables. All of the
original functionality of the Admin Interface remains unchanged.Here’s a shot of the new look:admin interface awesomesauce screenshotCustomizingIfsandman2ctldoesn’t give you fine-grained enough control over
your REST endpoints, or you’d like to restrict the set of tables made
available viasandman2ctl, you can easily integratesandman2into your application. See thedocumentationfor more
info.Runningsandman2under Dockersandman2has an official docker image atDocker
Hub. Simplydocker pull jeffknupp/sandman2to get the latest version. It
supports the most popular database engines, but not all thatsandman2currently natively supports. If you’d like to see support
for your RDBMS, either add a pull request on this repo (if possible) or
create a new issue with the details of your database’s Python driver.ExampleHere’s how one would runsandman2to connect to a PostgreSQL
database running on one’s host machine (i.e. not a remote database,
which is far simpler) under Docker(on a Mac, explained below):$ docker pull jeffknupp/sandman2$ docker run-d-eDB_TYPE=postgres-eDB_DRIVER=psycopg2-eUSERNAME=jknupp-eDB_HOST=host.docker.internal-eDATABASE=jknupp-eDB_PORT=5432-p9000:5000 sandman2$ curl localhost:9000/metaor open a browser tohttp://localhost:9000/admin/Note, ``DB_HOST=host.docker.internal`` is only necessary for databases
that reside on the host system (and the value only works on macOS).To
connect to a database on a remote machine, simply replace that value
with the machine’s IP or hostname.ParametersHere are the parameters available to specify your connection information
and their meaning:$DB_TYPE- The type of RDBMS to connect to (e.g.postgresormysql)$DB_DRIVER- The name of the Python library to use as a driver
(e.g.psycopg2orpymysql)$USERNAME- Database username$PASSWORD- Database password$DB_HOST- Database IP or hostname$DB_PORT- Database port$DATABASE- Name of database to connect toPass each value separately to thedocker runcommand with-e<VARIABLE>=<VALUE>. Not all are required, but which ones are
required differs based on your target RDBMS.