Search…
Python: heavyai
The heavyai client interface provides a Python DB API 2.0-compliant HEAVY.AI interface. In addition, it provides methods to get results in the Apache Arrow-based GDF format for efficient data interchange.

Documentation

See the GitHub heavyai repository and for documentation:

Examples

Create a Cursor and Execute a Query

Step 1: Create a connection
1
>>> from heavyai import connect
2
>>> con = connect(user="heavyai", password= "HyperInteractive", host="my.host.com", dbname="heavyai")
Copied!
Step 2: Create a cursor
1
>>> c = con.cursor()
2
>>> c
Copied!
Step 3: Query database table of flight departure and arrival delay times
1
>>> c.execute("SELECT depdelay, arrdelay FROM flights LIMIT 100")
Copied!
Step 4: Display number of rows returned
1
>>> c.rowcount
2
100
Copied!
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.
1
>>> c.description
2
[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)]
Copied!
Step 6: Iterate over the cursor, returning a list of tuples of values
1
>>> result = list(c)
2
>>> result[:5]
3
[(1, 14), (2, 4), (5, 22), (-1, 8), (-1, -2)]
Copied!

Select Data into a GpuDataFrame Provided by pygdf

Step 1: Create a connection to local HEAVY.AI instance
1
>>> from heavyai import connect
2
>>> con = connect(user="heavyai", password="HyperInteractive", host="localhost",
3
... dbname="heavyai")
Copied!
Step 2: Query GpuDataFrame database table of flight departure and arrival delay times
1
>>> query = "SELECT depdelay, arrdelay FROM flights_2008_10k limit 100"
2
>>> df = con.select_ipc_gpu(query)
Copied!
Step 3: Display results
1
>>> df.head()
2
depdelay arrdelay
3
0 -2 -13
4
1 -1 -13
5
2 -3 1
6
3 4 -3
7
4 12 7
Copied!