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.19.tar.gz (69.4 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.19-cp313-cp313-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.19-cp313-cp313-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.19-cp313-cp313-macosx_15_0_x86_64.whl (570.3 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.19-cp313-cp313-macosx_14_0_arm64.whl (564.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.19-cp312-cp312-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.19-cp312-cp312-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.19-cp312-cp312-macosx_15_0_x86_64.whl (570.3 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.19-cp312-cp312-macosx_14_0_arm64.whl (564.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.19-cp311-cp311-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.19-cp311-cp311-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.19-cp311-cp311-macosx_15_0_x86_64.whl (570.3 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.19-cp311-cp311-macosx_14_0_arm64.whl (564.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.19-cp310-cp310-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.19-cp310-cp310-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.19-cp310-cp310-macosx_15_0_x86_64.whl (570.3 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.19-cp310-cp310-macosx_14_0_arm64.whl (564.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.19.tar.gz
  • Upload date:
  • Size: 69.4 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.19.tar.gz
Algorithm Hash digest
SHA256 5231baf699831c1a2e4cfcbd2b4933ec7c499d575e076d44718a4f40f37b7359
MD5 86c145a7568f03a971cfdbf7c9b73016
BLAKE2b-256 f5fa21ea3ee6a3487a8449f541391c897dc43053a314c886457f0613d4871777

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19.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.19-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 14e278e9dff0e66963af099583fe762de0fd7938494a3719a72e3dc4517c3ddb
MD5 2294544f565bc979e16d912e7ba8c0bf
BLAKE2b-256 85db88fa005b9cd2078e7bf32f4e0bacbc3dc917a42d4a369c85255d71520c38

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp313-cp313-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 96874f1724ef8c6875a1e0958d286c34083da7555e9c481acaba57cf0466b285
MD5 7a36616abf64223cf16ad345f8348659
BLAKE2b-256 9f645f16f50675f1ba1205c28032ca1262203f32e52bf16bda63c785f12dcf51

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp313-cp313-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 038e99ad03119d46f33cecca7b1d42fb6d9bc4d18079da2861efcd998ccd20d2
MD5 5e27609bc6f89639c159a269fb5e069b
BLAKE2b-256 59e3d54536914daa98ce6cd11e1a193f27d454d07325472a0df524fab84046ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a2a39fec383a64d45e180db46caa30401e5a10c3f09a7355a011b841b591fe6d
MD5 de11a9fcefcef8a04d0e4dec22d23ad9
BLAKE2b-256 429e51a3075f47108fa5534aba5629d497cff253f6ce82029d156fcc12d84c60

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c1e890ab2188268d8fb1701bb2937f16c0d68a8b5eb1436592a065be539f3917
MD5 0855e9acff68ab68f0aca41f5c8fefc7
BLAKE2b-256 d9c1354ef883c8602416e04844227cead16327231ebcf84756ebb0f7e5875d04

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ff3e60f1b325f81afdc0b183ef01c52fee68db8fa7d1997b2a578dd5b322c443
MD5 939fcf2de719415bbd21151e9467ecb5
BLAKE2b-256 4ec6bbef795397e91f15527f2c377eea6dea1c929216fbf14636a3f37088d559

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp312-cp312-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7dd81b9db3df7880b3c07cdc652a4f11f0f1fa3005b00ac4fed97562dd6eb304
MD5 42b0a334491d14d47bca360a94976db0
BLAKE2b-256 7e9938c063e6f1a2ccb32dd999a001349b56d8d8ab0fb0cd8b99c47b6b8f6196

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 244cc634d74280e629705b28f364d7bdeb225e8574e3b2501a8e4cdcc789a7ab
MD5 195ab820aad940542036e2323a513288
BLAKE2b-256 f05e3a0235f762fa3722fa5331a44e3228e8e7a29e0a8f8620234b88ceaea17f

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26541f6f4230be95edd77d5e96f7b3a380ddcfc4708681e1caa4ac355d55a929
MD5 5629e654ceb7dae4ab0c351950f9f6ce
BLAKE2b-256 fd1c52688d7a32b506940bbd46bd480af8d207d4d20b907a9fd2887189bdb7e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp311-cp311-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 95f3b99f355170a52c29ee2fc661a01edc472fae14e02272c74477004ba9ebd3
MD5 fcac0f1641642bce4430ca4b0eae0462
BLAKE2b-256 7c8329ca9961785730db613ea73c048dcdfc86d104749e9b108c9361d18f78e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp311-cp311-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0b32a8512f07741218a6db596f77cc90c520dbdbc6c93e36fe2e60f17d2b6d18
MD5 e1ab76edd9cb8a08cc8fd1146074e7b2
BLAKE2b-256 a775763efc947a64865647593a57ba3e952518f536d5e5435c4734dd4f4f75d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f63858127fe0f9b7f0ae0d7a62dec74bd9373bbe30ae7e1669a24e61afe5bfde
MD5 d79662e1a0085e292b59d5d9feae37c5
BLAKE2b-256 fff1627e5d4e0924038ab18642d77bca6f964d303d6e79b697f45e1e2d94964b

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fa5dd10d7ca1bf3dde97b460e0a5dc90cf9a9dc1039226e89d0adef3230a5c3a
MD5 a1ffee14bef46582caf5a6127e37f2e3
BLAKE2b-256 5ddf7c641863911d2a17a29de7648fad54c5068f46dd9f3e698cbd675231f392

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp310-cp310-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7d20f06db79f905c279aa8d47c519dcf771ea03c178902149be9682190dbab58
MD5 d269ddd3ea13b4e01f9c72ba4e99dd1a
BLAKE2b-256 ac1f2202f1ba95b8c7daaaf0c9491e4823c06dd0a6d0d3f263f04b59af7c984c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp310-cp310-macosx_15_0_x86_64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 efed75fc253050753d787373bcedbfb346b88f6e19da6d4a2bcbc8df8c16b48e
MD5 acfe5f705a703df7d0879378b203670a
BLAKE2b-256 fb81db3611e22d150021f1cada33bf1379aedc1bb888eb66027942be26a8ff6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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.19-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.19-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1229e91b669fe5efc4170d34cec3af35604823d4d2dbcfd610108940edc07d71
MD5 ff502ff5600ebb7bf158b27b70c1b47c
BLAKE2b-256 ff36cdd39c3d3c7bf534d2ad8d18862e58d7479fe25c553cc3274a0eb2128540

See more details on using hashes here.

Provenance

The following attestation bundles were made for hogql_parser-1.3.19-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