Public Trilogy models.
Project description
trilogy-public-models
Overview
This repository contains semantic models on public datasets for the Preql/Trilogy language.
This supports the interactive PreQL demo, but can also be used by anyone to boostrap exploration of these public datasets.
You can install this library directly and import models to use.
Installation
pip install trilogy-public-models
Examples
This repository also contains a examples/ folder, which can be browsed for in-depth code examples.
Local Usage
This example assumes you are querying Bigquery Datasets.
To utilize a model, instantiate a standard PreQL executor (in this case, a bigquery client) and then pass in one of the existing environments from this package into the environment argument.
That will enable you to run queries against the semantic model.
from google.auth import default
from google.cloud import bigquery
from preql.executor import Executor, Dialects
from sqlalchemy.engine import create_engine
from trilogy_public_models.bigquery import google_search_trends
project, auth = default()
bq_client = bigquery.Client(auth, project)
engine = create_engine(f"bigquery://{project}?user_supplied_client=True",
connect_args={'client': bq_client})
exec = Executor(
dialect=Dialects.BIGQUERY, engine=engine,
environment=google_search_trends
)
results = exec.execute_text("""
SELECT
trends.term,
trends.rank,
trends.week,
trends.refresh_date,
WHERE
trends.week > '2023-01-01'
and trends.refresh_date = '2023-02-22'
and trends.rank < 10
ORDER BY
trends.week desc,
trends.rank asc
limit 100;
""")
# you can execute multiple queries separate by a semicolon
# so our results will be in the first element of the arra
for row in results[0]:
print(row)
Combining Models
Coming soon!
Preql supports combining multiple environments into a single environment. This enables simplified querying of universal concepts, like looking up StackOverflow links embedded in Github commits, or merging GPS data across different domains.
Contributing
Model setup
All models should be in a double nested directory; first the platform and then the semantic label of the model
Models should have the following
- entrypoint.preql
- README.md
Model Tests
All models will be imported and verified. Validation methods will depend on the defined backend.
All models require that the datasets being shared with the preql validation account.
Current verifications:
- model imports successfully
- datasource bindings exist
- datasource to concept mappings are appropriately typed
- concept relations are consistently typed
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
Hashes for trilogy_public_models-0.0.20.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6418035c5a2501adcf2b2ec961f6825e1788a734e5be44faea24a55813bfa967 |
|
MD5 | 8d9ea93fcc44e9daa6d83134fb426fdf |
|
BLAKE2b-256 | 30bafcc98030e13995ce558781052de5799599a3abfd6adc2ac14bb932123613 |
Hashes for trilogy_public_models-0.0.20-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e1259bc675a627734a5efa28f89779056d8f853048aee7fa80e79f7eb49aea1 |
|
MD5 | 0080d57725513c51ee060e92a3b6d1cf |
|
BLAKE2b-256 | a55189c847536a33b4de82c4293d8703d3de6e1c32337dca0aa70d4207b6555c |