Skip to main content

A semantic layer for your data.

Project description

Tesseract OLAP

A semantic layer for your data, enabling OLAP operations over relational databases. Tesseract OLAP provides a Python interface to translate multidimensional queries into optimized SQL, executing them against a backend, and returning the results in a structured format.

Key Capabilities

  • Multidimensional Analysis: Supports standard OLAP operations like drilling down, slicing, dicing, and pivoting.
  • Backend Agnostic: Designed to work with various data backends. Currently supports ClickHouse with specialized drivers.
  • Schema Validation: Uses a robust XML schema definition to validate queries and ensure data integrity.
  • High Performance: leverages polars for efficient data handling and transformation.
  • Caching: Built-in support for caching query results to improve performance (supports Redis).

Installation

Install the package using pip:

pip install tesseract-olap

Optional Dependencies

To use specific backends or features, install the corresponding extras:

  • ClickHouse Backend:
    pip install "tesseract-olap[clickhouse]"
    
  • Redis Caching:
    pip install "tesseract-olap[redis]"
    

Getting Started

In its most basic form, the tesseract-olap package provides a way to translate OLAP-type queries into request statements that a data backend can understand and execute safely.

1. Define your Schema

Tesseract uses a schema to define cubes, dimensions, and measures. Supported formats include XML, JSON, and YAML. See the OLAP Model Concepts and examples in the repository for schema details.

2. Initialize the Server

from tesseract_olap.backend.clickhouse import ClickhouseBackend
from tesseract_olap import OlapServer

# Initialize the backend connection
backend = ClickhouseBackend("clickhouse://user:pass@localhost:9000/database")

# Create the server instance with the schema
server = OlapServer(backend=backend, schema="./path/to/schema.xml")

3. Execute a Query

from tesseract_olap.query import DataRequest, DataQuery

def get_data():
    # Create a request object defining the query
    request = DataRequest.new("cube_name", {
        "drilldowns": ["Time", "Country"],
        "measures": ["Units", "Price"],
    })

    # Validate and compile the request against the schema
    query = DataQuery.from_request(server.schema, request)

    # Execute the query
    with server.session() as session:
        # Fetch results in different formats
        # result = session.fetch(query)           # Returns a Result object
        # result = session.fetch_records(query)   # Returns a list of dicts
        result = session.fetch_dataframe(query)   # Returns a Polars DataFrame

    return result.data

if __name__ == "__main__":
    data = get_data()
    print(data)

The server instance can be integrated into web applications (like FastAPI or LogicLayer) to provide a full-fledged OLAP API.


© 2022-2024 Datawheel, LLC.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

tesseract_olap-0.22.8.tar.gz (110.4 kB view details)

Uploaded Source

Built Distribution

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

tesseract_olap-0.22.8-py3-none-any.whl (137.7 kB view details)

Uploaded Python 3

File details

Details for the file tesseract_olap-0.22.8.tar.gz.

File metadata

  • Download URL: tesseract_olap-0.22.8.tar.gz
  • Upload date:
  • Size: 110.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-1010-azure

File hashes

Hashes for tesseract_olap-0.22.8.tar.gz
Algorithm Hash digest
SHA256 6cc0180b5c572d24f6ddbfbb2ee987831f9efde5b7624b80b91f6f9be70651ad
MD5 4b44dc8c6b676e34ea43e32996106818
BLAKE2b-256 8d4bcc86196035752ef2d3573a24152b9f625c08d5f062ca74ed277b21e97c96

See more details on using hashes here.

File details

Details for the file tesseract_olap-0.22.8-py3-none-any.whl.

File metadata

  • Download URL: tesseract_olap-0.22.8-py3-none-any.whl
  • Upload date:
  • Size: 137.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.12.3 Linux/6.17.0-1010-azure

File hashes

Hashes for tesseract_olap-0.22.8-py3-none-any.whl
Algorithm Hash digest
SHA256 4ef96c195f72a864d32db93df52eb491c81908f24f58cc7ed3bcd8925a1818cc
MD5 417303f254d8fc51a590925b5002459e
BLAKE2b-256 d8c3445ed7b172f3bf2d6346e26da2b5b81accaef111e3bc1034f866df6caab3

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