Arrow Flight Samples
If writing your client in Python or Node.js, we highly recommend using the respective Python SDK or Node.js SDK instead of using the Arrow Flight endpoint directly.
Alternatively, you can use the PyArrow package directly.
The Arrow Python bindings (also named β€œPyArrow”) have first-class integration with NumPy, pandas, and built-in Python objects. They are based on the C++ implementation of Arrow.
Queries can be sent and results retrieved as Pandas DataFrames. An example follows:
1
from pyarrow import flight
2
​
3
apiKey = '[API_KEY]'
4
query = 'SELECT * FROM eth.recent_blocks LIMIT 10;'
5
​
6
# Connect to the endpoint
7
client = flight.connect(f'grpc+tls://flight.spiceai.io')
8
​
9
# Authenticate with your app's API key
10
token_pair = client.authenticate_basic_token('', apiKey)
11
options = flight.FlightCallOptions(headers=[token_pair])
12
​
13
# Query and fetch a reader for the results
14
flight_info = client.get_flight_info(flight.FlightDescriptor.for_command(query), options)
15
reader = client.do_get(flight_info.endpoints[0].ticket, options)
16
​
17
# Convert to a Pandas DataFrame and print the results
18
print(reader.read_pandas())
Copied!
Stand-alone samples can be found in our sample repository:
  • ​Blocks Schema - Retrieve the structure only of blocks information.
  • ​Block Mining Time - Aggregation example to plot Average mining time of block per day of the week (last 1M blocks)
  • ​Weekly Gas Usage - Aggregation example to plot the average gas usage per weeks (last 3M blocks)
Export as PDF
Copy link
Edit on GitHub