PSPS Help Sections Software Components PSPS User Tools Project Wikis Related sites * -- restricted access

Connecting Directly to the Data Retrieval Layer

The DRL API allows us to write client side programs that can access PSPS data via Simple Object Access Protocol. On this page we provide an examples of a simple standalone program that can send queries to the DRL and a return the result set from the appropriate database. One can use this sort of program in a "robot" or "crawler" in a shell script to query a database repeatedly in an automated fashion.

Note: If you make your own program to do repetitive queries, please give some sleep time of a couple minutes between queries so that the DRL does not get bogged down.

Perl Example

One example we provide is a Perl program named which is attached to this page. This demonstration application was written by PSPS software engineer Conrad Holmberg. As attached, the program is set to query the SDSS database (SCHEMAGROUP= MOPS and SCHEMA = MOPS). To run this program you will need to change the user name "dummy_username" and the login password "dummy_password" to your login and password. To run the program, we put one or more queries into a file "query.sql" and provide the name of an output file which will receive the query results. Then, at the command prompt one types

perl -t fast -q query.sql -o outputfile.csv

The -t option is for either fast or slow queries. Note that if you use a slow query be sure to use the "SELECT INTO mydb.tablename" syntax. If our query file contains the line

SELECT det_id, field_id, ra_deg, dec_deg FROM detections LIMIT 10

the file outputfile.csv will contain the following result set:


If we change the line

use constant SCHEMAGROUP => 'MOPS';


use constant SCHEMAGROUP => 'PS1_SCHEMA';

and the line

use constant SCHEMA => 'MOPS';


use constant SCHEMA => 'PanSTARRS_3PI';

we can run a query against the ODM version of the 3PI database. In particular, we can submit the query

SELECT TOP 10 objid, ra, dec, gMagBest, rMagBest from Object

and get the result set


To run more than one query per input file, terminate each individual query with a semicolon. Do not terminate the final query this was as the program will expect another query in the list and terminate with an annoying (but harmless) error message.

Other Languages

The example shown above uses the Perl scripting language. The PSI application developed by the Pan-STARRS project uses essentially the same method illustrated by this Perl script, but programmed in PHP. The key point is that if one has a software library that can speak "SOAP" your software can make a connection to the DRL by following the simple protocol outlined above. As to whether your favorite programming language has a SOAP library is an exercise left to the reader to explore on the web.

Java Example

The source code for a Java example is in To use it, open the file and add your username and password into the appropriate global variables. To compile, type the following within the console:


To run

java DRLClient -q sample.sql -t fast -o output.txt

Python Example

The source code for a Python example is in To use it, open the file with an editor and add your username and password into the appropriate global variables. To run it, just use three arguments in this order: the name of the sql file, the name of the output file, and the type of query (fast or slow).

Note: You need the python library suds in order to run this.


python sample.sql output.txt slow
Last modified 5 years ago Last modified on 08/23/13 15:54:59

Attachments (3)

Download all attachments as: .zip