The easiest and quickest way to connect from Python code to Data Virtuality Server is the psycopg2 module. It uses the PostgreSQL protocol and has been specially designed for heavily multi-threaded applications.
For development and testing purposes, you can obtain a stand-alone package not requiring a compiler or external libraries by installing the psycopg2-binary package from PyPI:
In production, it is advised to use the package built from sources, as described in detail in the Installation section of the psycopg2 documentation.
Connect to Data Virtuality Server
As Data Virtuality Server and PostgreSQL share some part in their language, psycopg2 can be used for easy-to-set-up access to Data Virtuality Server. It can be used with plain SQL statements to be sent to Data Virtuality Server.
Using psycopg2 has some limitations. Let's consider the following example where something has gone wrong - note that we're employing the very helpful
mogrify method for it. Basically, all you need to do is replace
mogrify, and it'll return the exact string that would be sent to the database by
In the statement
"SELECT %s, %s, %s;", (dt, dt.date(), dt.time()), the placeholders are filled by Python via
(dt, dt.date(), dt.time())
. As a result,
::time are sent to the Data Virtuality Server (or, in our example, printed out by
mogrify) and prevent the statement from being parsed and understood. Thus, such statements cannot be used with psycopg2. But the following statement will work all right: