pymapd

The pymapd client interface provides a python DB API 2.0-compliant OmniSci interface. In addition, it provides methods to get results in the Apache Arrow-based GDF format for efficient data interchange.

Documentation

See the GitHub pymapd repository for full documentation:

Examples

Create a Cursor and Execute a Query

Step 1: Create a connection

>>> from pymapd import connect
>>> con = connect(user="mapd", password= "HyperInteractive", host="my.host.com", dbname="mapd")
>>> con
Connection(omnisci://omnisci:***@my.host.com:6274/omnisci?protocol=binary)

Step 2: Create a cursor

>>> c = con.cursor()
>>> c
<pymapd.cursor.Cursor object at 0x7f0117fe2490>

Step 3: Query database table of flight departure and arrival delay times

>>> c.execute("SELECT depdelay, arrdelay FROM flights LIMIT 100")
<pymapd.cursor.Cursor object at 0x7f0117fe2490>

Step 4: Display number of rows returned

>>> c.rowcount
100

Step 5: Display the Description objects list

The list is a named tuple with attributes required by the specification. There is one entry per returned column, and we fill the name, type_code, and null_ok attributes.

>>> c.description
[Description(name=u'depdelay', type_code=0, display_size=None, internal_size=None, precision=None, scale=None, null_ok=True), Description(name=u'arrdelay', type_code=0, display_size=None, internal_size=None, precision=None, scale=None, null_ok=True)]

Step 6: Iterate over the cursor, returning a list of tuples of values

>>> result = list(c)
>>> result[:5]
[(1, 14), (2, 4), (5, 22), (-1, 8), (-1, -2)]

Select Data into a GpuDataFrame Provided by pygdf

Step 1: Create a connection to local OmniSci instance

>>> from pymapd import connect
>>> con = connect(user="mapd", password="HyperInteractive", host="localhost",
... dbname="mapd")

Step 2: Query GpuDataFrame database table of flight departure and arrival delay times

>>> query = "SELECT depdelay, arrdelay FROM flights_2008_10k limit 100"
>>> df = con.select_ipc_gpu(query)

Step 3: Display results

>>> df.head()
depdelay arrdelay
0 -2 -13
1 -1 -13
2 -3 1
3 4 -3
4 12 7