Skip to main content

Public Trilogy models.

Project description

trilogy-public-models

Overview

This repository contains semantic models describing public datasets as Trilogy data models.

You can use this to quickly get started with Trilogy, or just as a place to find fun data to explore.

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

To expose models in the studio, run the 'build.py' script under the studio folder.

Examples will be picked up from matching subdirectories under the 'examples' folder.

Installation

pip install trilogy-public-models

Examples

This repository also contains a examples/ folder, which can be browsed for in-depth code examples.

Quickstart

This will import and set up a duckdb engine with a SF .5 environment.

from trilogy_public_models import data_models
from trilogy_public_models import get_executor

executor = get_executor("duckdb.tpc-ds")

QA_1 ="""
select 
    store_sales.date.year, 
    count(store_sales.customer.id)->customer_count
order by 
    store_sales.date.year desc ;
"""  # noqa: E501

results = executor.execute_text(QA_1)

for row in results[0].fetchall():
    print(row)

Advanced Usage

This example assumes you are querying Bigquery Datasets.

To utilize a model, instantiate a standard Trilogy 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 trilogy.executor import Executor, Dialects
from sqlalchemy.engine import create_engine

from trilogy_public_models.bigquery import google_search_trends
from trilogy_public_models import get_executor


# use default auth
exec = get_executor('google_search_trends')

# or provide client explicitly
# if using more complicated auth
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)

You can access all models through the data_model object:

from trilog_public_models import data_models

for k, v in data_models.items():
    print(k)
    _ = v.environment # environment

Combining Models

Trilogy 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.

Use the standard trilogy toolkit of merges to do this.

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


Download files

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

Source Distribution

trilogy_public_models-0.1.14.tar.gz (38.1 kB view details)

Uploaded Source

Built Distribution

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

trilogy_public_models-0.1.14-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

Details for the file trilogy_public_models-0.1.14.tar.gz.

File metadata

  • Download URL: trilogy_public_models-0.1.14.tar.gz
  • Upload date:
  • Size: 38.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for trilogy_public_models-0.1.14.tar.gz
Algorithm Hash digest
SHA256 97f36d8e461fc8d159c7039ca2b485b5adacd6c8a204d8012ff4d25f6173c7ba
MD5 851ec59151829e9b475f806955e44eec
BLAKE2b-256 7cabdfd8a0a7076149539288b66b2453bef4d2a0bb2b926b1a7fbe7706b399ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for trilogy_public_models-0.1.14.tar.gz:

Publisher: pythonpublish.yml on trilogy-data/trilogy-public-models

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trilogy_public_models-0.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for trilogy_public_models-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 1073f8a81de9b6405b5edc264be98c14d5b2d9de3280bb8adf2e1ce17fa8b30a
MD5 b8c35f465735a3088d10dba4bb9b93aa
BLAKE2b-256 2a848d50637fe398cd415a0e992a927c7f7c65851ebfe83bc6cbd0066a575a9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for trilogy_public_models-0.1.14-py3-none-any.whl:

Publisher: pythonpublish.yml on trilogy-data/trilogy-public-models

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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