Skip to main content

Python functions for Cube projects using cube.py config file.

Project description

Cube Utils

Cube Utils is a Python library for parsing and extracting information from query payloads.

Installation

You can install Cube Utils using pip:

pip install cube-utils

If you are using Cube, just add cube-utils to your requirements.txt file. e.g.

cube-utils

Usage

Here is an example of how to use the extract_cubes and extract_members functions from the cube_utils.query_parser module:

from cube_utils.query_parser import extract_cubes, extract_members

# Example payload
payload = {
    "dimensions": ["test_a.city", "test_a.country", "test_a.state"],
    "measures": ["test_b.count"],
    "filters": [
        {"values": ["US"], "member": "test_a.country", "operator": "equals"}
    ],
    "timeDimensions": [
        {
            "dimension": "test_c.time",
            "dateRange": ["2021-01-01", "2021-12-31"],
            "granularity": "month",
        }
    ],
}

# Extract cubes
cubes = extract_cubes(payload)
print(cubes)  # Output: ['test_a', 'test_b', 'test_c']

# Extract members
members = extract_members(payload)
print(members)  # Output: ['test_a.city', 'test_a.country', 'test_a.state', 'test_b.count', 'test_c.time']

URL Parameter Extraction

You can extract query parameters from a URL using the extract_url_params function from the cube_utils.url_parser module:

from cube_utils.url_parser import extract_url_params

url = "https://example.com/?foo=bar&baz=qux"
params = extract_url_params(url)
print(params)  # Output: {'foo': 'bar', 'baz': 'qux'}

Running Tests

To run the tests, use the following command:

python -m unittest discover tests

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

cube_utils-0.1.5.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cube_utils-0.1.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file cube_utils-0.1.5.tar.gz.

File metadata

  • Download URL: cube_utils-0.1.5.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.25.3 CPython/3.13.5 Linux/6.11.0-1015-azure

File hashes

Hashes for cube_utils-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b275be25d5320ad7363d9a32efee907b550274e58a38b2c8cf600cb341930eaf
MD5 8019b19d52aa09486b06aeb84450d83a
BLAKE2b-256 073edae104f81753778053149ded8240fc22a09888647b2d538af0d2f9dfb7ba

See more details on using hashes here.

File details

Details for the file cube_utils-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: cube_utils-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.25.3 CPython/3.13.5 Linux/6.11.0-1015-azure

File hashes

Hashes for cube_utils-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 14bef0494d541c29ad8792c7b38d75f770f33a180c7a23dc550508296f9be793
MD5 61998ddae12c82b71b14b662f6b82f0a
BLAKE2b-256 2aa53c08baa532397efd2674477004de6cb724f5f0b955e74151b6d7de1d6301

See more details on using hashes here.

Supported by

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