Skip to main content

HogQL parser for internal PostHog use

Project description

HogQL Parser

ANTLR4-based parser for HogQL and Hog, available as both a Python C++ extension and a WebAssembly module for JavaScript/TypeScript.

Packages

Package Runtime Registry
hogql_parser CPython (native C++ extension) PyPI
@posthog/hogql-parser Any JS environment (WebAssembly) npm

Both packages share the same C++ parser core and ANTLR4 grammar, so they produce identical ASTs.

npm package (@posthog/hogql-parser)

Installation

npm install @posthog/hogql-parser

Usage

import createHogQLParser from '@posthog/hogql-parser'

const parser = await createHogQLParser()

// Parse a HogQL expression
const exprAST = JSON.parse(parser.parseExpr('1 + 2'))

// Parse a SELECT statement
const selectAST = JSON.parse(parser.parseSelect('SELECT event FROM events WHERE timestamp > now()'))

// Parse a Hog program
const programAST = JSON.parse(parser.parseProgram('let x := 42; return x;'))

All parse functions return JSON strings. On failure they return a JSON error object instead of throwing:

const result = JSON.parse(parser.parseExpr('!!!'))
if ('error' in result) {
  console.error(result.type, result.message) // e.g. "SyntaxError ..."
}

API

Method Description
parseExpr(input, isInternal?) Parse a HogQL expression
parseSelect(input, isInternal?) Parse a SELECT statement
parseOrderExpr(input, isInternal?) Parse an ORDER BY expression
parseProgram(input, isInternal?) Parse a Hog program
parseFullTemplateString(input, isInternal?) Parse a template string (f'...')
parseStringLiteralText(input) Unquote a string literal

Setting isInternal to true omits position information from the AST.

Python package (hogql_parser)

Installation

pip install hogql_parser

The Python package is a native C++ extension and requires a platform with prebuilt wheels (macOS and Linux, x86_64 and arm64).

Local development

pip install ./common/hogql_parser

Building from source

Python

pip install ./common/hogql_parser

WebAssembly

Requires the Emscripten toolchain and Ninja.

cd common/hogql_parser
npm run build

This compiles the parser to WASM and places the output in dist/.

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

hogql_parser-1.3.41.tar.gz (90.1 kB view details)

Uploaded Source

Built Distributions

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

hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.41-cp313-cp313-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.41-cp313-cp313-macosx_14_0_arm64.whl (660.3 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.41-cp312-cp312-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.41-cp312-cp312-macosx_14_0_arm64.whl (660.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.41-cp311-cp311-macosx_15_0_x86_64.whl (662.6 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.41-cp311-cp311-macosx_14_0_arm64.whl (660.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.41-cp310-cp310-macosx_15_0_x86_64.whl (662.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.41-cp310-cp310-macosx_14_0_arm64.whl (660.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file hogql_parser-1.3.41.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.41.tar.gz
  • Upload date:
  • Size: 90.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hogql_parser-1.3.41.tar.gz
Algorithm Hash digest
SHA256 c3c8f0d46944f5f88e05bb5d800d9f673803050b2382f868948ee8471786f4ff
MD5 dd2b16218b3fb5f8b5a6a2344bf7b7ab
BLAKE2b-256 21afd325cfc28768e62c6c735965d83f31b5004cdd34f57d22c7030c177fd6ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41.tar.gz:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4b0a3f024a2b2372cc0329a215990f4ae9ab434823be703792a3b2cc41e4c2f0
MD5 1d76375f5b3f5db263ce1f9397ce3816
BLAKE2b-256 e2294d9674112ee591126c7c6e1a53a2d1d2913ebc7ce11bafdad4a4f8f62e24

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 92b47bcad3372eaf2e7612a4c96dcc655897f330f0736d022bea6452bf47e553
MD5 181e5a008f442b0a0969821ed4a21d5c
BLAKE2b-256 97607ac446159788a121f934a7c98d06ca161d44a3ba9066b71b8b9b3b26b59e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp313-cp313-manylinux_2_28_aarch64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp313-cp313-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 eb09172c975d1b1df006ec52142581877489eab3360ac04f62adac693170af19
MD5 34a62558c27fcb38b8b501583b15c2ee
BLAKE2b-256 410cf5230f7cfddc9b5b255cf03cfde68823d599f04942a0bea1dfc70a632004

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp313-cp313-macosx_15_0_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f7765c3798495f52528872dbc5e77e4820abac1cf6d4cdc6f287add0ac05f0c7
MD5 ab0280c43930e112a02895aa1a3e9a83
BLAKE2b-256 9286b571c2a045f9635a9a984d3b968ee357e1b6e4779186faee26df9608bbf1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7ce6ced81447500444e57dfa6488346c998592f37ba34274cd62021688470db5
MD5 f3839da7cef45df2d6de2a81c4222697
BLAKE2b-256 a8a0f8821ef1a1392668f8daba71876c5c1a9e3acf2d364eadfd651c76d5eced

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bcd6f7d84a72e9208b99c6b18e7a11a7a962aa1b35a35fbeea600c2fcd065c4b
MD5 19d92e0405b9b19627f24b6288e7e38d
BLAKE2b-256 d4b2ec1e998fc9658a2b48112c606e1293d2914f8717cebdfed2bd07a768fc1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp312-cp312-manylinux_2_28_aarch64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp312-cp312-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5bb5b0b999dcb38edd54ad2e09678c619ca19791da7a276c487ae954a02dbc10
MD5 f6ae6a7b6c65017d83c9f9b9e5ec5a6d
BLAKE2b-256 68c0119de44eb390ae5db7028c3e19368085248e0b3ea7575059f56f5e7e8feb

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp312-cp312-macosx_15_0_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d6ae65ff6ea222724724c64a33c1eca1fb80d86179b394d2f3b9eaee13067c40
MD5 2807ed12dd22801cfe0fefc2140bdde1
BLAKE2b-256 5f3f7d081d57dc12e9b965b71d42084b672e879d039096def4e1922d7b924b08

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3dfbb38213753e71f5fbd81d2c95030be1e6fd9ccf7750a81fc0fba76f61af21
MD5 adf7add9d38ae9f8c31fa026f9f369db
BLAKE2b-256 4439f50955afa9f97c2602f8e721c43f0b2e06aec1555184508c34ba55ab7217

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4a28762d99106340ab245abdf23ea0970a2fc6dcb695e0c9ef390fbc281dacbe
MD5 2b412c1a4f1317cbc3ab1296353a22a8
BLAKE2b-256 c4e3ebf07cc0326c88bc87c40b165e1c478e01940602364e34229374a4471354

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp311-cp311-manylinux_2_28_aarch64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp311-cp311-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 059a303bcc07fca177d1792d826755609debf1ebeeb4661d2632fb24c2591253
MD5 59add4b29a519eafcec33b282b05fb2c
BLAKE2b-256 575c939a62df36b058998776084fa7659ec8a8c9ece27b5f87150e45a0f58bb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp311-cp311-macosx_15_0_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a8a37c8bd77b7e4d0d093978a2a67c2c232c829acea46b3c6ddc0834dadee326
MD5 155102006980266c9dfe84a45877eb35
BLAKE2b-256 6a17a25929181b70db5d1251cb553ad981e38aff05e884ea7a0a1c17a991bb48

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca3d599744d95a85d867423386e00471d131064047acb04f1bd0711ac61af0bc
MD5 b047469789e2b8d7ab82b7bddef7d8f3
BLAKE2b-256 ea388206955ea950e6a1dd58b2e505d1b4434e0fd38e2ab67fa012a28ba2a427

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 28049015be5c8725b9df2a1da57a87344c66091089a04afb2b4330c1346da5c6
MD5 4e444d095289f571c355f687ace50b4b
BLAKE2b-256 9dea18c87a0af5c91a9403e56e481c6c93e567c64faf4b2590df3ef808139412

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp310-cp310-manylinux_2_28_aarch64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp310-cp310-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 81857f359a5b549e5a64c0f0795d7e3bc57b33f9d5336e5d19fbea1dd9d8add1
MD5 2ed9ba14ffee51e6d1e730a3b43b1770
BLAKE2b-256 fbca87c8ecc7ad836e138bf88e51d32c9aea8798e1c8f49ef9989918ff5fcf10

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp310-cp310-macosx_15_0_x86_64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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

File details

Details for the file hogql_parser-1.3.41-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.41-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 984c36ead478138fbb76fd17eaf44e5549e3eb1e22d4cc3398d5bbc75386be5a
MD5 c0cd3c713a01cbb63fec6efce2beb141
BLAKE2b-256 6ff77cd20904a4d0e70fdfa8e65bbef2bbb7159d7030d621c97442bbf965157e

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.41-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: build-hogql-parser.yml on PostHog/posthog

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