Search…
pyomnisci
The pyomnisci 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 pyomnisci repository for full documentation:

Examples

Create a Cursor and Execute a Query

Step 1: Create a connection
1
>>> from pyomnisci import connect
2
>>> con = connect(user="mapd", password= "HyperInteractive", host="my.host.com", dbname="mapd")
3
>>> con
4
Connection(omnisci://omnisci:***@my.host.com:6274/omnisci?protocol=binary)
Copied!
Step 2: Create a cursor
1
>>> c = con.cursor()
2
>>> c
3
<pyomnisci.cursor.Cursor object at 0x7f0117fe2490>
Copied!
Step 3: Query database table of flight departure and arrival delay times
1
>>> c.execute("SELECT depdelay, arrdelay FROM flights LIMIT 100")
2
<pyomnisci.cursor.Cursor object at 0x7f0117fe2490>
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 OmniSci instance
1
>>> from pyomnisci import connect
2
>>> con = connect(user="mapd", password="HyperInteractive", host="localhost",
3
... dbname="mapd")
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!
Last modified 3mo ago