Copying BQNT specific modules does not work for someone that has many different environments and many different versions of python.
Another way around it is to create a small local server. A sample working version with JSON serializer is below. BQNT env does not have flask, pyarrow and pickle does not work across different python versions.
This solution may appear a bit involving at first, but I think it is way simpler longer term. You never have to worry about these packages and consistency across them when setting up a new environment.
While the below works and it is similar the way Excel addin works, ensure that you are permitted to run it by checking with your representative.
A sample BQL call:
bql("""get(px_last)for('AAPL US EQUITY')with(dates=range(-1w,0d),fill='prev')""")
returns:
ID DATE CURRENCY px_last
0 AAPL US Equity 2023-05-15 USD xxxx
...
# notice that serializer kept datatypes correctly
> aapl.dtypes
Out[5]:
ID object
DATE datetime64[ns]
CURRENCY object
px_last float64
dtype: object
# a client version
def bql(query):
'''
>>> bql("""get(px_last)for('AAPL US EQUITY')with(dates=range(-1w,0d),fill='prev')""")
:param query:
:return:
'''
response = requests.post('http://localhost:8000', data={'query': query})
if response.status_code != 200:
raise Exception('Query failed with status code {}'.format(response.status_code))
data = pd.read_json(response.text, orient='split')
return data
# a version of a server
# the server can be started after setting path to BQNT env
# to get their path: open bqnt and run
# os.getenv('PATH')
# in a shell script set the path to point to BQNT env and start the server
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
length = int(self.headers.get('content-length'))
message = self.rfile.read(length).decode()
query = parse_qs(message).get('query')[0]
print(f'Received query: {query}')
try:
bq = bql.Service()
data = bql.combined_df(bq.execute(query)).reset_index()
result = data.to_json(orient="split")
self.send_response(200)
self.end_headers()
self.wfile.write(result.encode())
except Exception as e:
self.send_response(400)
self.end_headers()
self.wfile.write(str(e).encode())
if __name__ == "__main__":
host = 'localhost'
port = 8000
print(f'Server BQL starting on {host}:{port}') # Print host and port
httpd = HTTPServer((host, port), SimpleHTTPRequestHandler)
httpd.serve_forever()