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.77.tar.gz (93.0 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.77-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.77-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.77-cp313-cp313-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.77-cp313-cp313-macosx_14_0_arm64.whl (658.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.77-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.77-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.77-cp312-cp312-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.77-cp312-cp312-macosx_14_0_arm64.whl (658.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.77-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.77-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.77-cp311-cp311-macosx_15_0_x86_64.whl (668.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.77-cp311-cp311-macosx_14_0_arm64.whl (658.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.77-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.77-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.77-cp310-cp310-macosx_15_0_x86_64.whl (668.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.77-cp310-cp310-macosx_14_0_arm64.whl (658.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.77.tar.gz
  • Upload date:
  • Size: 93.0 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.77.tar.gz
Algorithm Hash digest
SHA256 54b2fea0d84355428f0007c56b52467c916aabb2edf4d81bdf6832981c33385d
MD5 d9ad7d495f25afcdb6e1c595850f816a
BLAKE2b-256 e5b0f8bfa5c99eb03a5590d534a6603ddd8b673c265fc7fe636f85118266b708

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb2937ce6885885435c0984617b99d2b702e6070c7eea5049296aa5fc1be4453
MD5 7904b8470cb88e103d450196ae5a8c0d
BLAKE2b-256 b7e32b344e224e4c69ded92a0a5eeb06bb132400c32de41d0e9d5915208deb79

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ace2fd1f1ece2fdcbbcf8c0f6ba331818b6dd9f2cd35a389e61a5fabd0b0f4d3
MD5 7ee5677b8f31b35f89b446cc152ad0f0
BLAKE2b-256 23a1c5870de8a1574be62c065ef81b91a8b5e4764a4643955ef6d0569eb5212e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6a957218ed655c1e7138c8b63a2ffce6af225a556d73d429edc8fbc13aec91e9
MD5 8f9d8f1b86e1f44b16979657e6ce5c4e
BLAKE2b-256 959dc9fd969c78d238fce27022f83fea8178ff9ff8983353898c7a571fdc093d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7ff9f8110e97600736d7a3bf12d98eace6bd74452ea9c27f7e2ebfc07e511436
MD5 1e249f2e4efdb0f088643bf545edd880
BLAKE2b-256 a8713c1b37e684534b9d8aac963dbf7ba04368ce224ce4f34f855b9452bf1517

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a7aeec38680757b037ff18691429e574c9a3d02017e3a13f37e379b2b13ee2f8
MD5 e02f38b4f0a714aeca60c156fdf37e7c
BLAKE2b-256 44de8ec93bf85cab79041afb6a05bfc2a3009247f0362e85192eeea7cd5ffdb8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a5ade3f2f95338783b5183f39fca2fdfd4b18470024edea4352825e71bd93fb8
MD5 e47425bacbbed89fad52469c522db037
BLAKE2b-256 1bd32de2326d19b9eff48e84506a4e9d573f6f9a8fce583b415cfa28c037c3fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 352152ea564073209a0cb5070af6a605f9c51fe092a9cfff9353d9178c3bbf4e
MD5 190ebba2a72942a1758c2352677280c8
BLAKE2b-256 1dc4c1019040a0e3e8743d7eb98b009d1579acaa24f0c78ff8029fd3f4e86f55

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e00dec11d49beb361b024629d8b2e70445588c6e5225256e31ef3dde0ff2412c
MD5 f97a0f93ca73b9fd8b8917daefaf8073
BLAKE2b-256 9b546f8376e8800b038283cae3333485672d4611e62aabe4053ad61277407aba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 50774019ef21347135509d89e199caa43d977c2af8839d45546e4c0d3df70c40
MD5 220711987f4047e6e90c6722f321c16a
BLAKE2b-256 7f544e678fbad70a47b2f853f005578d204aeb849e5fb289f9f64ac65b89352e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 42d89db48673318c6257e69d319611aedd86a7aec0856ed8960962e2521b9a28
MD5 85d658d2f63a5d5d509dbf89b9ece738
BLAKE2b-256 d5315f02b8860171eb9091feb95a566c9e88aa55fcc7787ecf5e58f2159b7600

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b903c40d2fd3846959aaaf0d74b7e47b7bdb7af0a231caa66fd5803ac8e46f4d
MD5 7b7e0b4f536d7160634e37bd906884ac
BLAKE2b-256 659a4bd34dd942b471fb8f919f357f82b0d828cc457d1fe5c8952a8aaed490f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 63ffb5e2f41dd2c143635e217e6ad368742fd0a0581a4f2ad5d578249ef240bd
MD5 64154beeb94f4770620b24abebed0551
BLAKE2b-256 c111c5c1edb8bbdec158ba7fe5c3ac1100271f75e0de94da7e90eae1be5a24bb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e70cbf7631bc53799a55af9463e1d917eb37a732b81cbc19a0f9794c06f01542
MD5 b967c3adf0cadae9db7eb62df9589888
BLAKE2b-256 0f551ed1426c3ef6557c88a1e568716a6205fcafa8fa1c2be1e1cf87321bba49

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1e35e57db5d3048cf8bccea234939feed1e12c34effcf3648ca572675f364e08
MD5 a8170a331562ea3631dd15b4f44b9b34
BLAKE2b-256 7a1d8c7759be98939667a578a9058b5200fc04c03e556b056432eca8b765380b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 dc45662cbbabc212bae93673677f2532f1dac08a4f95467f8dc28c109a8815df
MD5 a8770b125ff070c46e8e6b694ff8def6
BLAKE2b-256 84f3cb00b92d3a0b7d71ada7a207a6c76cb5ff1bbfaadc4f760d9a56e634b891

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.77-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6718d022ae53af67bca14ee3c67a541dc0c6f69d6303c46477b42e88fd263574
MD5 ed13fdfe9dd9ebb32bfbc1827d8ff44d
BLAKE2b-256 6718a3bbe3c89248235519f6fc5c2958b32e11b75b0b9b1ce22be2599f142947

See more details on using hashes here.

Provenance

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