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.18.tar.gz (69.3 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.18-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.18-cp313-cp313-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.18-cp313-cp313-macosx_15_0_x86_64.whl (569.0 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.18-cp313-cp313-macosx_14_0_arm64.whl (563.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.18-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.18-cp312-cp312-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.18-cp312-cp312-macosx_15_0_x86_64.whl (569.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.18-cp312-cp312-macosx_14_0_arm64.whl (563.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.18-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.18-cp311-cp311-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.18-cp311-cp311-macosx_15_0_x86_64.whl (569.0 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.18-cp311-cp311-macosx_14_0_arm64.whl (563.9 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.18-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.18-cp310-cp310-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.18-cp310-cp310-macosx_15_0_x86_64.whl (569.0 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.18-cp310-cp310-macosx_14_0_arm64.whl (563.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.18.tar.gz
  • Upload date:
  • Size: 69.3 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.18.tar.gz
Algorithm Hash digest
SHA256 3e7c341ce2def4274b60872d53bc672407124a0b6e389b9626da81d76de11321
MD5 abf62a203f434e88d923fc395186c9d7
BLAKE2b-256 9ee4328afcc1c49353c5784e0f915fc0784f00f008acde9ddec37dfa41394366

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0892d5360e0bd91eb70e81fa489dc72e32cd3a236d0ee8ef5464b5875803a0e0
MD5 17470f74314ca50245dc6642cf6f325f
BLAKE2b-256 429fa7541e925f8b99829410ea297a2d8d71cdf18c70648f81463e589848660a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 529c40fb362c3c2c986a58a9a72ed7be3c79c58022912cd0d676ffb74403c6e4
MD5 c26d1803b2dabb1a13575dc17dcbdaac
BLAKE2b-256 398c4d4a363dc988b16cafb38ceb3f55a28546852a06864bd66cfc0001f4f860

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c67d24e510c9b039e9302da7e8e8ddeee6b64e923474a4ebd87da28f180a2521
MD5 e11ac776c79aafda1ebfe59ef0c1855d
BLAKE2b-256 490e55b2125ad84b02391b8dc7e9f04d6b9d7870c7e556c8b28c523a5a8ab90c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d16183a17513e7334a511ac729c262a4979d376096648735dc5c434e9df92215
MD5 1868d463fa021bb9a749a2ad9096ce58
BLAKE2b-256 d53fc06bbc616e742ac23616e6c86bc2ef8ae413a776d897f013f11cd4f18036

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 002992f0c988b886ec12aabe8239061828b42cae09da5ed0122106720ffc6915
MD5 354215c5e2afc858ab96717d7f887cd6
BLAKE2b-256 190debec783fa7fa56893bcb129c1daa4633b899c4855735cf63d3180b87f010

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 af3659c21481ef2a1d386fcafacd5addaf8a270dd0fd7892f88aa82b891c902c
MD5 448fae14feaf71a0829347e285bf2f25
BLAKE2b-256 5a16e71e3da1d90419a278d93de5d6dfda701cfbf2446318618e9bb7a114e1c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c21d6e6f23147feaf5cec198610fbf25be155e82cba54a8d6d58eee1b9a1047c
MD5 01262062eaf1230b03e8fc2adb8752c4
BLAKE2b-256 245248124e7c587ddba7e0840c914cced0883456d05f976f45830f20a5db1d0c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bb866984db38051b4ab028debe72f901a097716ab50bc935efeb82a09fb0125c
MD5 c8a42b4f4eb45147f31451b9cdaa1899
BLAKE2b-256 5fbbe410868be86283b6289023e667e217ac052e5b58ea1279261297224e13b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f79c3e976f1cc9f3e60b264476b52b40b89948ea1cef970348e865b2e7ab7cd5
MD5 3cc8c45326e05741ad9c9b716087b003
BLAKE2b-256 2fe795f6dc2989c21d81db8e86addf30f6323a44a91e9bfe4f7716691cd7d431

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d98a1626fdf90b8a8a4dae744c755cc6f4ebfcb51670f5b77affe7e0df60c5d9
MD5 b35b68bff287cd7f56200c3249900253
BLAKE2b-256 c70a6078f10c39be4437eeb8b61f61c4c60bec686e0f16702e79e15f98053502

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 591d88a1f1930b80b9eee7f472c4b9041ab6e633ac682166733263c1795085b6
MD5 6da4bf811010e0d9e8f2ea1a4e74e16b
BLAKE2b-256 9911f584e6da57cc4d7086489d6fdf513185c7fdf80e5b5a863a1d96d8cc16d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 757e9ba28f308911bb2126e7d03c42627d418a6d02ce9fd7598171af8b47d903
MD5 8b244470ef0aa49d70d68210755a33f5
BLAKE2b-256 25ba711cabdecc29e049b204f28fd3da8796c292fe2e09e6905afc3fe6a814f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0e8ff236938e1bb52a1c073e781e1033c46f2cc9ed0a710238d3885b6f6ef0a7
MD5 93e1dd5c9dccd6927ff8c975ee5efdc9
BLAKE2b-256 a94d7c5a982a8b51ed08888bd5e43a03835ced4cfb1bc12127a88f1cf5267107

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89a16d16a45653954936065954357acd129a8c978713e4fd7753b40ef290c0b9
MD5 ed2a0b20a60a4c22bec38a63296d8d23
BLAKE2b-256 165c76afe61c185a71b56bb6068b87630d4977385a393e9fcb76f36d159d2ba7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 574091aee65149ff2d8667984f87adc17484df5bbe8ca9bd3ce0224bed9348fe
MD5 cfa2d8ded0217eb35772c0cc593fcb97
BLAKE2b-256 dd3b8f71764abfd08e524d1d3a73dce9eae51f6ee47727c2e69742c94729f615

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.18-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 657fd6126cce9003fc6da387334670d03a442be80111da482013e11ebb6b624d
MD5 91b91d2707d37ccbcf9be0584024d3ea
BLAKE2b-256 851f45abab7c99bebce85064f4d32ce05f3b1a3862f72663c2f98510fef6a012

See more details on using hashes here.

Provenance

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