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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.21-cp313-cp313-macosx_15_0_x86_64.whl (569.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.21-cp313-cp313-macosx_14_0_arm64.whl (564.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.21-cp312-cp312-macosx_15_0_x86_64.whl (569.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

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

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.21-cp311-cp311-macosx_15_0_x86_64.whl (569.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.21-cp311-cp311-macosx_14_0_arm64.whl (564.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.21-cp310-cp310-macosx_15_0_x86_64.whl (569.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.21-cp310-cp310-macosx_14_0_arm64.whl (564.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.21.tar.gz
  • Upload date:
  • Size: 69.7 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.21.tar.gz
Algorithm Hash digest
SHA256 bd0592c13bfdd36c6a57ad7abbc7114d88c43c48ac10ec864e54cd885bfb3c1e
MD5 068a25bd3b2132576fc9bb35bf7a9c25
BLAKE2b-256 d61a8fc9cf3750a325b86618eaa7992ae388211e6c05fad5f877b2ae3e09b010

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 00a5ebe0a12df4fcd0be75f5119a33535c63ed82a8c733dafa2739e36104d735
MD5 27849bf0ce3cfd5a5968b913976546b0
BLAKE2b-256 62730066c9c84ffe64fee109742899583231a7242610e178369f550938e5e3f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 321f6b8a60303b09319f6a1d5f2c7ffb0d005b32437d5e1e591ffa870fac8bc6
MD5 14fbeb7cad50da1fa96fc1f970efc34e
BLAKE2b-256 afd6937e1b86a61ad0594fcd45d846cbb072137f86dedf0830aba36323fcbfeb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a84690b7b59f1ba63c30f72c56ba90aad180eb3b928902c8af2824e28aae71d3
MD5 148c34daba76aae8a58f403f8b38b5c9
BLAKE2b-256 4cf545027fd3dceab28f9bd41058e72a27e93bce5d51ffb254758e9e86f6fdfc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 60896e477022b80236d929235a583416c99d702fb249827d5a724f8b2c161f04
MD5 f25e9092fb3bd579a3ac47d10fcc670b
BLAKE2b-256 e27839d61030b667febd10fbc86d957f57074e16f13148cbf5e56078d044a2a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 353b8d1171b14627db5308b17961a8863bb71b72d0b13083eff10cca452a560f
MD5 15c9752c4dd89d6c8e7a199bd8b3c436
BLAKE2b-256 54087419e4a5123983c87b21136945957ed3f090aa90fd9bd20567a39711466d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f221ba50932618ae34449c180db10d8d4b8f4240eedb851bfbdaddae47f56dbb
MD5 1f84d5f7928e74550ac156bf0cc56192
BLAKE2b-256 385ac00daa1e623ca53f9350c4985e3edf0f43b5e23643a89e85af816d97865b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7a6cbfd7c827f116936753d7fe5f38b0d0f8b76c8ef3409dd808202274b74721
MD5 4555f5ec8bbf675f428681b821188c87
BLAKE2b-256 114440248dce5f4e569f53a3456741db0dfae852ff9a929e3823302308f0f704

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4f440738e0a18fe28a3ce6f939191d248a29b5e2e602ff33b4b6cefa04c3dbe6
MD5 2e520682d99b677e817dbbe958f054e8
BLAKE2b-256 7b5b80ad48969d0279dd6432dbf1b685ae43be45f6fb0718c102ae9bf138c0f7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de1679127486a03462df3422bc7f460030b56092f8c34a86bff20d4f0438a907
MD5 6338d57c247576bab7d34cd45de4f7c0
BLAKE2b-256 fd7b6b5abb46145df4ce4d0a71c88a4947dd74ebed267e721eec42229e3e60ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c460100b69ed232041e92bbef8775745967f56b261a34dc7fc78dae198681f95
MD5 49f8653134837899fd241a4adbb2efc9
BLAKE2b-256 1475ce8454efe485a887dc6bd72aa467fa896d64b13fb91bceecd734d5a533b8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f3565744016432d5ed81085866d16284f48bc6bd12461cb323d46a8307e28248
MD5 f013e89da163da8a05ca1c82b9712511
BLAKE2b-256 124714ec2d81ee0cd0352119ca5643be420d740c59b2d074b846e6eb6120950d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b37bde8877e7fda90d53ade8060afda6f90a46989d024dc8a8a03235203c4489
MD5 fea22f83a0e50a60def2657c502d72a1
BLAKE2b-256 c9e12875205e0c081ca58ac21cd4477534b61c08a901ccc4d6751097db31aaa9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bd1be6d2a2c3baf79a08ec4aa2cd22396f7aebdbf6e223873e726ec1c2fe7a6
MD5 eb62553d59c39760a4a4cdf7b7ec60b8
BLAKE2b-256 1128c169d3a492b3698e5f699a0ddbed3677f0cb6580c41784abf50aedb25ba5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 19b7da55094c5661f5e2307359c8209371ab41c1e1ff4e55ca0190683a395a1a
MD5 473eb925ebff79a9c496fafd12c58992
BLAKE2b-256 6e3f4e680bbdb4ead065f329be553b708677534da89ba8808cd92e6133969006

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 85909e3a94de844b67b3a53087a77ff1990d084b8fb612961caf3dae2530dbd5
MD5 f3679ad7ff19728b9a7b8c54eb843e13
BLAKE2b-256 23be1169aa4760f23ea8c3b354901b0d80c07f637916462412e7749fa77100ff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.21-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0649f538cf2e56e22165cc0a1006a7fffc8dbe958a88434ed719285fd96a08f1
MD5 18ba4423fbe465ee86a8c57ae464e10d
BLAKE2b-256 5d9c93f3c0287937c90868993a4ddea976442ab3ed243ab1cf55aa69107721f4

See more details on using hashes here.

Provenance

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