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
-
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
-
Initialize the Connection:
from LookerDF import Connect looker_ini_path = 'path_to_your_looker.ini' connection = Connect(looker_ini_path)
Running Queries
- 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)
- 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
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
Built Distribution
File details
Details for the file LookerDF-1.0.1.tar.gz
.
File metadata
- Download URL: LookerDF-1.0.1.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eaac4c56c9ae6934e0f925e7cc5fe9955a1c02adaec86fc0238445f218034c6 |
|
MD5 | f577ee42a7ead166fbd507d424d71ff6 |
|
BLAKE2b-256 | dc339dcb018525225dafbfd912629b3c75a5cf868edb814636752764f0b53859 |
File details
Details for the file LookerDF-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: LookerDF-1.0.1-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da0acb0f9494236e24aab9e504fbe13b15ac2683faf322ac96aac6636b0d97b5 |
|
MD5 | 5a9a246f855714e39c653291babdde35 |
|
BLAKE2b-256 | 201caad581267aee9dec7fe839fe37e57b771536bdab493ec04af65424fb3264 |