立方体.jsPython客户端
CubeJsClient的Python项目详细描述
立方客户端
Cube.jspython客户端!它协助令牌管理,并通过重试抽象HTTP请求。你还需要运行一个实例立方体.js对其运行请求的服务器。此客户端不提供任何绘图功能。在
文件
立方客户端
初始化
fromcube_js_clientimportCubeJsClient,client=CubeJsClient(server,# required - the running cube.js serversecret,# required - the api token or secret needed for requestsbase_path='cubejs-api',# optional - the basePath, needed of not using the defaultload_request_timeout=60,# optional - timeout for a single request to cube.js serverload_waiting_max_requests=50,# optional - number of requests to make while waiting for a responseload_waiting_interval=1,# optional - time to wait between requeststoken_ttl={'days':1},# optional - timedelta kwargs for how long the token is validadd_headers=None,# optional - any additional headers to add to the request)
负载
^{pr2}$Note:如果多维数据集拒绝请求,则可能引发cube_js_client.CubeError
Note:如果负载耗尽了load_waiting_max_requests
,则可能引发cube_js_client.CubeTimeoutError
sql
client.sql(request_body# required - json request to send to cube.js)
记录
若要查看记录的事件,请重写log方法并记录应用程序需要记录的内容:
classMyClientClass(CubeJsClient):deflog(self,level,msg,**log_variables):print(f"[{level}] {msg}",log_variables)client=MyClientClass(server,api_token)
示例
fromcube_js_clientimportCubeJsClient,CubeError,CubeTimeoutErrormy_client=CubeJsClient("http://my_cubejs_server.com/","theApiToken",add_headers={'user_id':1})try:results=my_client.load({"measures":["Cube.count"],"dimensions":["Cube.dimension"]})print(results)exceptCubeError:print("Cube rejected")exceptCubeTimeoutError:print("Request to Cube timed out")
今后的工作
- 请求
meta
- 综合文件
- 测试
- 自动格式化
- 缓冲响应处理
常用命令:
黑色格式
$ black cube_js_client --config cube_js_client.toml
许可证
在立方体.js客户端是MIT licensed。在
- 项目
标签: