Skip to content

Commit acc0d48

Browse files
authored
Merge pull request #3 from spicehq/corentin/spicpy
Change pyarrow to spicepy
2 parents a7cedf5 + 4155b9d commit acc0d48

File tree

1 file changed

+4
-26
lines changed

1 file changed

+4
-26
lines changed

snippet.py

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
1-
import os
2-
from pathlib import Path
3-
import ssl
4-
import tempfile
5-
import urllib.request
6-
7-
from pyarrow import flight
8-
9-
10-
# Check for gRPC certificates
11-
if not (Path(Path.cwd().absolute().anchor) / 'usr' / 'share' / 'grpc' / 'roots.pem').exists():
12-
env_name = "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH"
13-
if env_name not in os.environ or not Path(os.environ[env_name]).exists():
14-
tls_root_certs = Path(tempfile.gettempdir()) / "isrgrootx1.pem"
15-
if not Path(tls_root_certs).exists():
16-
ssl._create_default_https_context = ssl._create_unverified_context
17-
urllib.request.urlretrieve("https://letsencrypt.org/certs/isrgrootx1.pem", str(tls_root_certs))
18-
os.environ[env_name] = str(tls_root_certs)
19-
20-
client = flight.connect('grpc+tls://flight.spiceai.io')
21-
headers = [client.authenticate_basic_token('', 'API_KEY')]
22-
options = flight.FlightCallOptions(headers=headers)
23-
24-
query = 'SELECT * FROM eth.blocks ORDER BY number DESC LIMIT 10;'
25-
flight_info = client.get_flight_info(flight.FlightDescriptor.for_command(query), options)
26-
reader = client.do_get(flight_info.endpoints[0].ticket, options)
1+
# Install with: pip install git+https://github.com/spicehq/spice-py
2+
from spicepy import Client
273

4+
client = Client('API_KEY')
5+
reader = client.query('SELECT * FROM eth.recent_blocks ORDER BY number DESC;')
286
print(reader.read_pandas())

0 commit comments

Comments
 (0)