Name | trilogy-public-models JSON |
Version |
0.1.7
JSON |
| download |
home_page | None |
Summary | Public Trilogy models. |
upload_time | 2024-11-26 14:08:28 |
maintainer | None |
docs_url | None |
author | None |
requires_python | None |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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.
## Installation
```bash
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.
```python
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.
```python
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:
```python
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.
## 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
Raw data
{
"_id": null,
"home_page": null,
"name": "trilogy-public-models",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "preql-community@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/cd/46/3925aa4b89f54c703abb1fcd680be52267f55ed0f470e8cb941b71a52a1e/trilogy_public_models-0.1.7.tar.gz",
"platform": null,
"description": "# trilogy-public-models\n\n## Overview\n\nThis repository contains semantic models describing public datasets as Trilogy data models.\n\nYou can use this to quickly get started with Trilogy, or just as a place to find fun data to explore. \n\n## Installation\n\n```bash\npip install trilogy-public-models\n```\n\n## Examples\n\nThis repository also contains a examples/ folder, which can be browsed for in-depth code examples.\n\n## Quickstart\n\nThis will import and set up a duckdb engine with a SF .5 environment.\n\n```python\nfrom trilogy_public_models import data_models\nfrom trilogy_public_models import get_executor\n\nexecutor = get_executor(\"duckdb.tpc-ds\")\n\nQA_1 =\"\"\"\nselect \n store_sales.date.year, \n count(store_sales.customer.id)->customer_count\norder by \n store_sales.date.year desc ;\n\"\"\" # noqa: E501\n\nresults = executor.execute_text(QA_1)\n\nfor row in results[0].fetchall():\n print(row)\n\n```\n\n## Advanced Usage\n\nThis example assumes you are querying Bigquery Datasets.\n\nTo utilize a model, instantiate a standard Trilogy executor (in this case, a bigquery client) \nand then pass in one of the existing environments from this package into the environment argument.\n\nThat will enable you to run queries against the semantic model.\n\n```python\nfrom google.auth import default\nfrom google.cloud import bigquery\nfrom trilogy.executor import Executor, Dialects\nfrom sqlalchemy.engine import create_engine\n\nfrom trilogy_public_models.bigquery import google_search_trends\nfrom trilogy_public_models import get_executor\n\n\n# use default auth\nexec = get_executor('google_search_trends')\n\n# or provide client explicitly\n# if using more complicated auth\nproject, auth = default()\nbq_client = bigquery.Client(auth, project)\n\nengine = create_engine(f\"bigquery://{project}?user_supplied_client=True\",\n connect_args={'client': bq_client})\n\nexec = Executor(\n dialect=Dialects.BIGQUERY, engine=engine,\n environment=google_search_trends\n)\n\nresults = exec.execute_text(\"\"\"\nSELECT \n\ttrends.term,\n\ttrends.rank,\n\ttrends.week,\n\ttrends.refresh_date,\nWHERE\n trends.week > '2023-01-01'\n and trends.refresh_date = '2023-02-22'\n and trends.rank < 10\nORDER BY \n trends.week desc,\n trends.rank asc\nlimit 100;\n\n\"\"\")\n\n# you can execute multiple queries separate by a semicolon\n# so our results will be in the first element of the arra\nfor row in results[0]:\n print(row)\n\n\n```\n\nYou can access all models through the data_model object:\n\n```python\nfrom trilog_public_models import data_models\n\nfor k, v in data_models.items():\n print(k)\n _ = v.environment # environment\n```\n\n## Combining Models\n\nTrilogy supports combining multiple environments into a single environment. This enables simplified querying\nof universal concepts, like looking up StackOverflow links embedded in Github commits, or merging GPS\ndata across different domains. \n\nUse the standard trilogy toolkit of merges to do this. \n\n## Contributing\n\n### Model setup\n\nAll models should be in a double nested directory; first the platform and then the semantic label of the model\n\nModels should have the following\n\n- entrypoint.preql\n- README.md\n\n\n### Model Tests\n\nAll models will be imported and verified. Validation methods will depend on the defined backend. \n\nAll models require that the datasets being shared with the preql validation account. \n\nCurrent verifications:\n\n - model imports successfully\n - datasource bindings exist\n - datasource to concept mappings are appropriately typed\n - concept relations are consistently typed\n",
"bugtrack_url": null,
"license": null,
"summary": "Public Trilogy models.",
"version": "0.1.7",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0684bbd27f80aef2c537aafdaa7a44aa8d5b389d800d9071c1c63f10b4262d35",
"md5": "61a9a960475cd8b03169437dd30f91e0",
"sha256": "e6d38bed4b22991f72b0e63c3ca72fc47a5ee385453232c936e055d823cfcc40"
},
"downloads": -1,
"filename": "trilogy_public_models-0.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "61a9a960475cd8b03169437dd30f91e0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 59911,
"upload_time": "2024-11-26T14:08:26",
"upload_time_iso_8601": "2024-11-26T14:08:26.999373Z",
"url": "https://files.pythonhosted.org/packages/06/84/bbd27f80aef2c537aafdaa7a44aa8d5b389d800d9071c1c63f10b4262d35/trilogy_public_models-0.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cd463925aa4b89f54c703abb1fcd680be52267f55ed0f470e8cb941b71a52a1e",
"md5": "80570dc57b830728e603a2a4bc2fd9a0",
"sha256": "7479f30da5871b3c54703efb9219362d1c556337c33fbcbdc60acbf37410d757"
},
"downloads": -1,
"filename": "trilogy_public_models-0.1.7.tar.gz",
"has_sig": false,
"md5_digest": "80570dc57b830728e603a2a4bc2fd9a0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 32937,
"upload_time": "2024-11-26T14:08:28",
"upload_time_iso_8601": "2024-11-26T14:08:28.980807Z",
"url": "https://files.pythonhosted.org/packages/cd/46/3925aa4b89f54c703abb1fcd680be52267f55ed0f470e8cb941b71a52a1e/trilogy_public_models-0.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 14:08:28",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "trilogy-public-models"
}