Skip to main content

Cube.js Client for Python

Project description

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

load operation

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

sql operation

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

CubeJsClient-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file CubeJsClient-0.1.1.tar.gz.

File metadata

  • Download URL: CubeJsClient-0.1.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for CubeJsClient-0.1.1.tar.gz
Algorithm Hash digest
SHA256 96b829c1745bce3c719dc3c49aadd67921f86afae00c4648b62c00b72f29832b
MD5 7b986425187dc8d49facac41543aa567
BLAKE2b-256 ee4d00346faae6d05ce561d63fc6a5ce302ad1d4d5e972b8b4424ef5b24fdb39

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page