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.64.tar.gz (92.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.64-cp313-cp313-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.64-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.64-cp313-cp313-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.64-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.64-cp312-cp312-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.64-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.64-cp312-cp312-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.64-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.64-cp311-cp311-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.64-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.64-cp311-cp311-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.64-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.64-cp310-cp310-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.64-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.64-cp310-cp310-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.64-cp310-cp310-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.64.tar.gz
  • Upload date:
  • Size: 92.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.64.tar.gz
Algorithm Hash digest
SHA256 1bec0c56048633dc6ab63c0a76034680ba66795f7a62a613b29ee8d551eb69dc
MD5 6c1af6cc81e025c481ba8d35750b3639
BLAKE2b-256 ee57f7e912892a5395620e652cfaad2d0b09c0394227c528dee1c1fc28a90a83

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d86ec12dea36755f05bbcd47ce133d6e1198639e68b636575b4bbf4695894ff5
MD5 e3f0eeb750163f1af4f17e1f3929ebc1
BLAKE2b-256 9aa8a5680e7d665888b9ee448885a8fc6796c6ce2bc6210a85af0f5c57254b7f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bc23136ae8819fd6fe0dd189c6678c8c705c6672f5bf9627d3aee5c78b82ada6
MD5 5ea51b3298d06f8d6966ae46cd8322f5
BLAKE2b-256 d93bfd21143498cf9ae279cba924c39618a0c333d4076136e2906e9a2118697a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0de026f48a3122fa2d45eaabe3b4b231abd8538574f62df2129b1f399ffb6f1d
MD5 433a6e1092130b62fde043e6f2c30dd6
BLAKE2b-256 4b429191080507a686c207ac78e1aa5dd8f7bf19199f2ac028a539b82584eaea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 afa3eb4bf076ee5ab5efdfdf86be0be1af70bc0d443204e5029d1061e11dca74
MD5 6f4394cb03f85c2b2e8d67f64c7910d4
BLAKE2b-256 3c5aad15a50ef655396bea31babef70ad3cd93e3d32a15004440c42e413e571c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d85f0210d7d3b94e906c714b3f06827ef3e23ba833b557a08fe07bb041c53283
MD5 9f7de800b8295b6c4656f95f713490b5
BLAKE2b-256 e8636e0e6260cadd88dfc20e71711ad1a0133badd0084cd77441327bb8b852a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 569c0b1f69e30a2d853f808ad1942cd6c04f433eee8280622734fcd266049ac9
MD5 e1589fbdb0eafed05e948d8b3d0644d6
BLAKE2b-256 443be9e69ca59a5097be46bc5063ca1688c9d58e7ba98e0eece17b636849199a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 aa058b85b0b49b489b846444d610c4a72bf73fa593f0eb5952d1c560801dcb05
MD5 4f3c2243abfec029c68a96733e488495
BLAKE2b-256 e09ff2d6800d47b7840fba469fdd7d2d4b199ef39ddce3c90c6763643ba2984e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4dd02d2cbf4eb5e75f298e8aca0f9df973bd20ba8908aa0866d1ca4aff39dfe6
MD5 1f80ac15b36c14b30594216fd581a567
BLAKE2b-256 c503206b4c812aee9bad61758ff43198f77ca8b6f2e7d2ba0338231412de24b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8fcbaaffb6bbf12acced380bb141ec90276054436cbea098471158e205ca239f
MD5 bd81878646d3001ab0b07ce563ac7db0
BLAKE2b-256 65555c2d2000d7ccc8de7ae0b4f272e5e562900472a622661892a3677acbf310

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4b560c957dc3fabf77f4dfe8c601b403e59f58aa1e8f6fa98d3b0d6553359301
MD5 6a308a009f9abba94ea6f18ffb700d54
BLAKE2b-256 03559ab7f18b70d9ccb2e58a0990d187df7c09fc2453cc793a6b75d92e758550

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 64c26e9e3d80f605f34ed571d009a331f94d3b1e1a7a7cce736f047c57817d6a
MD5 dcf72bfa100017c51ced80b4a982d458
BLAKE2b-256 380827890dcd52ef1874e29c68c2d5150ddef83e61fd24b6acbe268cddc70509

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7f8ce5082becd398ce38b3993e6b4f960d23749567e24889a4d4eeb187caa2d6
MD5 51c02847243696734f8b994730feba1e
BLAKE2b-256 4b19d9a50ae5b0729d89c69955b5a661ebdccbdd2a3a7bccc65880d572039ff6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 66b6af24524f522ca3c359eb71ceeb89398c05990a50c331053a033c9ce0cfcf
MD5 54ac99bd154dc24caacf48c09ed33fee
BLAKE2b-256 dfab833da89f89786ca2ae778dafdc8c841259841dc43bc91a8a46868bb04d85

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c613c2eb273d8659aabb18765c29a74b59654c5b2176e170939e44c0e5a3eb62
MD5 8347e2e8bf962fc4197f2d5c5dc74b5b
BLAKE2b-256 95fdc83f12cbee05e49d2e8c428ac6ee7391d6ce3a41ed760d2c5df94e5a81d4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8d5f0d3775513b9081c2a0b267c55fb3622e27f337da644f4cdafb2e57ab5a00
MD5 ba72806bd06b57a652b8ab3bc5d5063e
BLAKE2b-256 2bcd7fcf69b99842544932f0c26007fad65b2aa23ff587559fd6df8f5f92e516

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.64-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c24d3e2763059f1b653a1935ad174d9ca9a93ac3d91122d87497415e53a0de9a
MD5 ab81769536fd8a8562836d427d740883
BLAKE2b-256 100b7ee850b00beebefbb6df74a4b9846a61c0b67d0f194dc2ff480b3bc50935

See more details on using hashes here.

Provenance

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