analytics-query-analyzer
Analyze analytics SQL to extract referenced tables/columns and time bounds.
Support
BigQuery and Redshift are currently supported.
Install
Base install:
pip install analytics-query-analyzer
BigQuery extras (only needed for build_schema):
pip install analytics-query-analyzer[bigquery]
Redshift extras (only needed for build_schema):
pip install analytics-query-analyzer[redshift]
Usage
analyze
Extract table/column references from a query.
Schema format follows sqlglot conventions, with nested fields represented as nested dicts.
from analytics_query_analyzer import analyze
from sqlglot import dialects
schema = {
"production": {
"shop": {
"orders": {
"id": "int64",
"ordered_at": "datetime",
"user_id": "int64",
"payment": {
"amount": "int64",
"method": "string",
},
},
},
},
}
sql = """
select
id,
user_id,
payment.amount
from
shop.orders
"""
references = analyze(dialects.BigQuery, sql, schema, "production")
print(references)
# [
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "id",
# },
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "payment.amount",
# },
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "user_id",
# },
# ]
analyze with time bounds
Extract time bounds from filters by enabling with_timebounds.
from analytics_query_analyzer import analyze
from sqlglot import dialects
schema = {
"production": {
"shop": {
"orders": {
"id": "int64",
"ordered_at": "datetime",
"user_id": "int64",
},
},
},
}
sql = """
select
*
from
shop.orders
where
ordered_at >= "2025-01-01"
and ordered_at < "2026-01-01"
"""
timebounds = analyze(
dialects.BigQuery,
sql,
schema,
"production",
with_timebounds=True,
)
print(timebounds)
# [
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "id",
# "lower": None,
# "upper": None,
# },
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "ordered_at",
# "lower": "2025-01-01",
# "upper": "2026-01-01",
# },
# {
# "database": "production",
# "schema": "shop",
# "table": "orders",
# "column": "user_id",
# "lower": None,
# "upper": None,
# },
# ]
To make current_date() deterministic, pass a provider:
timebounds = analyze(
dialects.BigQuery,
"select * from shop.orders where ordered_at >= current_date()",
schema,
"production",
with_timebounds=True,
current_date_provider=lambda: "2026-01-01",
)
build_schema
Fetch a schema dictionary from BigQuery or Redshift.
from analytics_query_analyzer import build_schema
from sqlglot import dialects
schema = build_schema(dialects.BigQuery, "my_project", "my_schema", "my_table")
print(schema)
- Authentication uses Application Default Credentials (ADC).
- When
tableis omitted, it scans all tables in the dataset. - When both
datasetandtableare omitted, it scans all datasets in the project. - The returned
schemacan be passed directly toanalyze.
Fetching from Redshift is also supported:
from analytics_query_analyzer import build_schema
from sqlglot import dialects
schema = build_schema(dialects.Redshift, "my_database", "public", "orders")
print(schema)
Redshift authentication supports two modes:
- Set
REDSHIFT_HOST,REDSHIFT_USER, andREDSHIFT_PASSWORD(optionalREDSHIFT_PORT). - Set
REDSHIFT_CLUSTER_IDENTIFIER,REDSHIFT_REGION, andREDSHIFT_DB_USERto use IAM (you can also setREDSHIFT_HOST/REDSHIFT_PORT). - Use
AWS_PROFILEif you want to select a non-default AWS profile.
Metadata
Release files for analytics-query-analyzer 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| analytics_query_analyzer-0.6.0.tar.gz | 20.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| analytics_query_analyzer-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.3 kB
Release files / analytics_query_analyzer-0.6.0.tar.gz
| Download URL | analytics_query_analyzer-0.6.0.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9715d46e035b65c5d656df7dd5ea5d9a283e66eed1b28c678b5dd1bf1328be0c
|
|
BLAKE2b-256 checksum How to use checksums |
a49de32c8864286bd35b8d3825c0f963b31c8ab1018dfb87437e70d0fe7a3776
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 27, 2026.
Transparency logRelease files / analytics_query_analyzer-0.6.0-py3-none-any.whl
| Download URL | analytics_query_analyzer-0.6.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f0a9656a77b58409867be2174e2ba6edabed4c0717514d6fb418deec84d24ed2
|
|
BLAKE2b-256 checksum How to use checksums |
928c8268c81b234c82ae5f230c79170121b3cb22ea50bff5e37c46ae884688f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 27, 2026.
Transparency log