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.4.tar.gz (6.3 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.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cube_utils-0.1.4.tar.gz
  • Upload date:
  • Size: 6.3 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.4.tar.gz
Algorithm Hash digest
SHA256 630f43a6a61ebd3decfed775393d37e726233c3bc25fcc14e9a850fa9b967e7f
MD5 42c7a2012da42f3034596390c0374847
BLAKE2b-256 b39db7ee9d725416b28c30541a1fbfc527b17bd0244ad26c0087640d03ed5735

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cube_utils-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a159b7afffcfa1e66c5d18ff1d398523dad8eb2a947f3822e4dc8e0b3e6364bc
MD5 cf146e18c7d94157164ec4ed784d0377
BLAKE2b-256 2fb885ed2f4b0650b4be110c92c7349ea9f7f8dc29eea1106a5417f41f31b07d

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