RTGL: A framework providing a Relational Task Generation Language for Relational Deep Learning
Project description
RTGL
RTGL (Relational Task Generation Language) is a Python framework for writing compact, expressive predictive queries over relational data, especially for Relational Deep Learning.
It lets you write shorter, more expressive queries by abstracting temporal joins and complex aggregations.
🧠 Features
-
🎯 ANTLR-based Parser
- Lexer and parser for RTGL syntax
-
🌳 Structured parse-tree visitor
- Converts parsed queries into normalized dictionaries with source positions.
-
🔍 Semantic validation
- Schema-aware query validation with error reporting.
-
🔀 Two converters
- 📌
SConverterfor static prediction queries. - ⏰
TConverterfor temporal prediction queries with timestamp windows.
- 📌
-
⚙️ Dual output mode
execute=Falsereturns generated SQL.execute=Trueexecutes SQL and returns aTableobject.
⚙️ Installation
Install RTGL via pip:
pip install rtgl
🚀 Quickstart
1. Build your database as RelBench Database object or use simplified RTGL version
# path to classes
from rtgl.base import Database, Table
2. Static query with SConverter
from rtgl.converter import SConverter
converter = SConverter(db)
rtgl_query = """
PREDICT COUNT_DISTINCT(votes.*
WHERE votes.votetypeid == 2)
FOR EACH posts.* WHERE posts.PostTypeId == 1
AND posts.OwnerUserId IS NOT NULL
AND posts.OwnerUserId != -1;
"""
# SQL only
sql_query = converter.convert(rtgl_query, execute=False)
# execute and get Table(fk, label)
table = converter.convert(rtgl_query, execute=True)
3. Temporal query with TConverter
import pandas as pd
from rtgl.converter import TConverter
timestamps = pd.Series(...) # define timestamps for which prediction must be made
converter = TConverter(db, timestamps)
# also, it is possible to update prediction timestamps later without recreating converter
converter.set_timestamps(new_timestamps)
rtgl_query = """
PREDICT COUNT_DISTINCT(votes.*
WHERE votes.votetypeid == 2, 0, 91, DAYS)
FOR EACH posts.* WHERE posts.PostTypeId == 1
AND posts.OwnerUserId IS NOT NULL
AND posts.OwnerUserId != -1;
"""
# SQL only
sql_query = converter.convert(rtgl_query, execute=False)
# execute and get Table(fk, timestamp, label)
table = converter.convert(rtgl_query, execute=True)
4. Examples
For more comprehensive examples and use cases, check out the relbench_exp.ipynb notebook.
You can also check the rtgl-tasks repository for more tasks.
📐 Query Language
📌 Static query design
PREDICT <aggregation | expression | table.column> [RANK TOP K | CLASSIFY]
FOR EACH <entity_table>.<primary_key>
[WHERE <static_condition | static_nested_expression>];
⏰ Temporal query shape
PREDICT <aggregation | temporal_expression> [RANK TOP K | CLASSIFY]
FOR EACH <entity_table>.<primary_key> [WHERE <static_condition | static_nested_expression>]
[ASSUMING <temporal_condition | temporal_nested_expression>]
[WHERE <temporal_condition | temporal_nested_expression>];
🧮 Aggregations
| Function | Meaning | Condition-Compatible |
|---|---|---|
AVG |
average | ✅ |
MAX |
maximum | ✅ |
MIN |
minimum | ✅ |
SUM |
sum | ✅ |
COUNT |
non-null count | ✅ |
COUNT_DISTINCT |
distinct count | ✅ |
FIRST |
earliest value by time | ✅ |
LAST |
latest value by time | ✅ |
LIST_DISTINCT |
list of distinct values | ❌ |
🧭 Temporal window rules
- Window format:
<start>, <end>, <measure_unit>. - Supported units:
YEARS,MONTHS,WEEKS,DAYS,HOURS,MINUTES,SECONDS. - Window semantics are half-open:
(start, end]. PREDICT/WHERE:startandendmust be non-negative.ASSUMING:startandendmust be non-positive.startmust be strictly less thanend.
🏗️ Architecture
RTGL Query String
↓
[Lexer] -> Tokens
↓
[Parser] -> Parse Tree
↓
[Visitor] -> Structured Dictionary
↓
[Validator] -> Semantic Checks
↓
[Converter] -> SQL Query
↓ (optional execute=True)
[DuckDB] -> Result Table
🔧 Development
Install uv
- macOS & Linux
wget -qO- https://astral.sh/uv/install.sh | sh
- Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Install dependencies
uv sync --all-extras
Regenerate parser files
If you modify lexer or parser grammar files (*.g4), regenerate ANTLR outputs from the repo root:
./regenerate_parser.sh
Run tests
pytest
Run linter
ruff check .
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rtgl-0.0.4.tar.gz.
File metadata
- Download URL: rtgl-0.0.4.tar.gz
- Upload date:
- Size: 80.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d428e9b8750ffb86188fb8c97ee7c0ab794fd50cb1231bd734e811dba9dc222
|
|
| MD5 |
bf2fcca82d82ea4b6deae8361907a24a
|
|
| BLAKE2b-256 |
21975224bc0fdfa998a4ac4b20b799cff117deb76796e05dc1605edc23c02f53
|
Provenance
The following attestation bundles were made for rtgl-0.0.4.tar.gz:
Publisher:
publish-to-pypi.yml on kolesole/RTGL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rtgl-0.0.4.tar.gz -
Subject digest:
8d428e9b8750ffb86188fb8c97ee7c0ab794fd50cb1231bd734e811dba9dc222 - Sigstore transparency entry: 1726762457
- Sigstore integration time:
-
Permalink:
kolesole/RTGL@e843ff8f9741b4f526b889fd449dfcdd6380d40b -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/kolesole
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e843ff8f9741b4f526b889fd449dfcdd6380d40b -
Trigger Event:
push
-
Statement type:
File details
Details for the file rtgl-0.0.4-py3-none-any.whl.
File metadata
- Download URL: rtgl-0.0.4-py3-none-any.whl
- Upload date:
- Size: 90.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9df321b95260d3b60ab1c46ac6c076c6379705fb716d63cd7afc4062f0c1cef8
|
|
| MD5 |
012757c5f075db736cce5ee663a6e60d
|
|
| BLAKE2b-256 |
77c5681be595ac510676c5dce2890e7b04fd37f7cad3cc67b565cf82b1ec72ea
|
Provenance
The following attestation bundles were made for rtgl-0.0.4-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on kolesole/RTGL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rtgl-0.0.4-py3-none-any.whl -
Subject digest:
9df321b95260d3b60ab1c46ac6c076c6379705fb716d63cd7afc4062f0c1cef8 - Sigstore transparency entry: 1726762871
- Sigstore integration time:
-
Permalink:
kolesole/RTGL@e843ff8f9741b4f526b889fd449dfcdd6380d40b -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/kolesole
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@e843ff8f9741b4f526b889fd449dfcdd6380d40b -
Trigger Event:
push
-
Statement type: