©2008-2017 David V Keeney All rights reserved.
RdbHost provides databases as a webservice. The easy way to access your RdbHost database from Python is via the DBI module Rdbhdb.
The module follows the conventions of the Python DB API version 2 as far as possible. It does not work exactly the same as other PostgreSQL DB API modules, in particular with regard to transactions.
Here is a simple example that uses the server as a simple calculator, adding 1 and 1. This will work with any valid role on any database, as no specific privileges are required on any resource within the database.
The above example is a complete working script that executes the addition query on the server and prints the result.
There is complete documentation for the module in the module itself. The DB API itself is documented in Pep 249.
As a webservice, RdbHost does not offer true persistent database connections that can carry a transaction. It instead starts and completes a transaction for each .execute() method call. You can take advantage of PostgreSQL's transactions by writing blocks of SQL code with conditional commits and rollbacks and executing those blocks with .execute() calls.
The webservice limits the number of records returned from a query to 100. If you need more records than that, you can either write a sequence of queries to get the necessary records, or you can use a handy feature of the DB API module: the autorefilling cursor. Just set the autorefill attribute on the connection to enable autorefilling.
Any cursor can be used in autorefill mode. The autorefill mode catches the limit exception, rewrites the query with new offsets and limits, and requests more records. This mode is not enabled by default, because a few queries will give undesirable results when used like this.
If you do not wish to use the DBI module, database usage can be accomplished via Python http calls, through the standard library. See further details on that approach here.