CubeJsClient
Cube.js client for python! It assists in token management and abstracts the HTTP requests with retries. You still need to run an instance of the Cube.js Server to run requests against. This client does not provide any graphing functionality.
Docs
CubeJsClient
init
from cube_js_client import CubeJsClient,
client = CubeJsClient(
server, # required - the running cube.js server
secret, # required - the api token or secret needed for requests
base_path='cubejs-api', # optional - the basePath, needed of not using the default
load_request_timeout=60, # optional - timeout for a single request to cube.js server
load_waiting_max_requests=50, # optional - number of requests to make while waiting for a response
load_waiting_interval=1, # optional - time to wait between requests
token_ttl={'days': 1}, # optional - timedelta kwargs for how long the token is valid
add_headers=None, # optional - any additional headers to add to the request
)
load
client.load(
request_body # required - json request to send to cube.js
)
Note: Might raise a cube_js_client.CubeError if the Cube rejects the request
Note: Might raise a cube_js_client.CubeTimeoutError if the load exhausts the load_waiting_max_requests
sql
client.sql(
request_body # required - json request to send to cube.js
)
logging
To get visibility into logged events, override the log method and log however your app needs to log:
class MyClientClass(CubeJsClient):
def log(self, level, msg, **log_variables):
print(f"[{level}] {msg}", log_variables)
client = MyClientClass(server, api_token)
Example
from cube_js_client import CubeJsClient, CubeError, CubeTimeoutError
my_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)
except CubeError:
print("Cube rejected")
except CubeTimeoutError:
print("Request to Cube timed out")
Future Work
- Requests for
meta - Comprehensive Documentation
- Tests
- Auto-formatting
- Buffering response handling
Common Commands:
Black Formatting
$ black cube_js_client --config cube_js_client.toml
License
Cube.js Client is MIT licensed.
Release files for CubeJsClient 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| CubeJsClient-0.1.1.tar.gz | 3.8 kB | Details |
Release files / CubeJsClient-0.1.1.tar.gz
| Download URL | CubeJsClient-0.1.1.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96b829c1745bce3c719dc3c49aadd67921f86afae00c4648b62c00b72f29832b
|
|
BLAKE2b-256 checksum How to use checksums |
ee4d00346faae6d05ce561d63fc6a5ce302ad1d4d5e972b8b4424ef5b24fdb39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.5
|