Skip to main content

Simple get data from Looker API into Pandas dataframe

Project description

LookerAPI Python Library

This Python library allows you to connect to Looker, run queries, and retrieve data as pandas DataFrames. This simplifies the process of interacting with Looker's API and makes it easier to analyze data using pandas.

Installation

To use this library, you need to have the Looker SDK installed. You can install it using pip:

pip install looker-sdk
pip install pandas

Usage

Setup

  1. Configuration: Create a configuration file (e.g., looker.ini) with your Looker API credentials. The configuration file should look something like this:

    [Looker]
    base_url=https://your.looker.instance
    client_id=your_client_id
    client_secret=your_client_secret
    
  2. Initialize the Connection:

    from LookerDF import Connect
    looker_ini_path = 'path_to_your_looker.ini'
    connection = Connect(looker_ini_path)
    

Running Queries

  1. Simple Query:
from your_library_name import GetData

df = GetData.get_query(
    sdk=connection.sdk,
    model='your_model',
    view='your_view',
    sort_by='your_sort_field',
    sort_type='desc',
    limit=100,
    fields=['field1', 'field2'],
    filters={'field': 'value'}
)

print(df)
  1. Look Query:
df = GetData.get_look(
    sdk=connection.sdk,
    look_id=123,
    limit=100
)

print(df)

Classes and Methods

Connect Class

Methods:

__init__(looker_ini_path): Initializes the connection to Looker using the provided ini file. make_sdk(looker_ini_path): Creates the Looker SDK instance.

GetData Class

Static Methods:

get_query(sdk, model, view, sort_by, sort_type='', is_total, fields, filters, limit=500): Runs a Looker query and returns the data as a pandas DataFrame. get_look(sdk, look_id, limit=500): Retrieves data from a Looker Look and returns it as a pandas DataFrame.

Example

Here's a complete example of how to use the library:

import pandas as pd
from your_library_name import Connect, GetData

# Initialize connection
looker_ini_path = 'path_to_your_looker.ini'
connection = Connect(looker_ini_path)

# Run a query
df = GetData.get_query(
    sdk=connection.sdk,
    model='your_model',
    view='your_view',
    sort_by='your_sort_field',
    sort_type='desc', 
    limit=100,
    fields=['field1', 'field2'],
    filters={'field': 'value'}
)

print(df)

# Get data from a Look
df = GetData.get_look(
    sdk=connection.sdk,
    look_id=123,
    limit=100
)

print(df)

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

LookerDF-1.0.0.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distribution

LookerDF-1.0.0-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

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