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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.63-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.63-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.63-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.63-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.63-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.63-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.63-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.63-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.63.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.63.tar.gz
  • Upload date:
  • Size: 92.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.63.tar.gz
Algorithm Hash digest
SHA256 301ad4bec3fe030c3def6b26135906be54930e80b5b9c659c50f183d3aff7f9f
MD5 849f8614536489cba91b74f670f48a59
BLAKE2b-256 45c2995fe9ae784e836a282b2a5faea45be6253cc389b9e8e7b99944b8d83276

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcf0cbfea78eedfe850700c17d4264d8db8240e9db108c6d375354b9e8953ad4
MD5 347bc2c478d19a57d0358b289174ed13
BLAKE2b-256 699e8325607af4542fc0e8e7bf74d2c8dd951bed569dd51776f5d45cfd1cc231

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3e743acf145aaaf6a8abd076c62ccda13996d5a43019afac3682d428f38ff950
MD5 ff146a2b57d19e5e21d14663443f9b46
BLAKE2b-256 ded52b451fe242ee4aee4aed4c542632ed4d4fa1106a7f63161f5e5d0da1b621

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ca724556252e954a803eee1a84500cda34e8ce5cb515d782c7989577f6c9289b
MD5 a959f46f42dd03d576a0f315eb416f6d
BLAKE2b-256 6b38aa3e41fa1ad7ba4720e79eec529467e8a7dd21178dab8dc817b492f5c474

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 709c6dde7e8d208003611688237e88afa59dc9fa5224b19eff1f8762ba71542e
MD5 18a7d4952df246448899ff01155f8174
BLAKE2b-256 c6a370685a56e13a42ebed347641bcca144187963791cc5bc3cced8c08b64841

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e2e44cb32c0dd5f96e30ff5ce41fc2ebd5ec706a94a5d348e850725b0ab2af9
MD5 d55e5e7897d486816a598f0cf96e6a9e
BLAKE2b-256 ba533752c196810c32e9e745530cd7a2234a103755cfa00c2bf490dda7848986

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5a916eb6d532112959b8bb5d722438c7f52677f01f5d3b4a0f3540a59979bc75
MD5 158244a9ae9034671b79e6365624ba24
BLAKE2b-256 973ac47cf3b56ee503409632ef00d6d4b84c69b2529b76a0cf35eaeb14667698

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 87b8a6a1cdfceeadcc06ed78415f34b686b670121baec5dd599ab55d3496437f
MD5 957950ce0c1663a8162a30a69911b148
BLAKE2b-256 329adc3ac211d2e85fea9cad3c51624dc1c2bc82a6b3bfc607f7ecb988f3ef3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d4288ad574744626957cc79bcd94819c2bbc9bbbb8ee645d2e2dd0805c7b08ab
MD5 5dc09a6b5cbaa5103b265c9dd9df4e97
BLAKE2b-256 dff282080add93dec200287c9da434919006f4f48cdcc22e797190b148a9bfd4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bda55f3322fda2aee03fc61cc2c464b82590443ade6b46c27873bdabfcf1768c
MD5 a3bc04538153b9705fc704cdf277fdf3
BLAKE2b-256 6023726a7734d5a4c5320f3af1a5a7a7f0563b5b61cb637aa046c5ab17904bc6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 503f125f124d4d1c6b6e9344e306e59013c763120ea7f4a6481725338bea1ecd
MD5 0b02f620cf94c8cf91c3541c67d99d23
BLAKE2b-256 b2fdfaaea3bd582ccaf52b0ff909765efbe946adaa5ec3b3654ad0a695aa8abe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b891c81ea93e72dd2ad5fc3948489ac93a07156be50e9ed1b1afbe3b5419e32a
MD5 dd29813897bf8c40405dd5f82d904207
BLAKE2b-256 16909b19c6a1189f11797642956b45e59447e35cb9dfc250df7cdfc105bd509e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e8301791c39e5183f1fa77085d3a211a3652a9fbc9013c66992a9687bbcd8878
MD5 8b980a4945bf6ad765d225ee948865bd
BLAKE2b-256 5f2a843d95b9a17d92d5aa6dba22c5d4af3e1d827559139022e53e6f2d344b04

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 427ae58b63792449458b6973ce7151379d6804a90ff02d087714ee00ff4662d3
MD5 ba83fe2f53d64d0fe4f7a3c663c7e5ca
BLAKE2b-256 3b14007e24f6117c1f7b6f17f4af93df0a8b246cd409f72d82f2885382e38229

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0bf927fc77ec64e0bffc183cc43c58e821ec214dbe0b301ea854b023a7de3e97
MD5 024b9ddb54159fb93b4b0090251926e1
BLAKE2b-256 2f68efcfcb5a7f6f191374c7ad6f7c0ebe4f8de88b31e5285a5a18304677fa66

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a66f8d277da42a2a66d1920f5466aac46a8e8e9ea19bcaf86d8a66d7a57b741b
MD5 c1a45985bbb727ea6aa9502ee61dca89
BLAKE2b-256 e08d7ea86cc35e6e6115e617e6b9db842b4e9a826a8440eea8ecc2dfa128f845

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.63-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1b9cb7f57b1d85f4eb24dd1173d86ac3ed8f4b04fc120e0742cdce59c880891b
MD5 d8dc87ac2f8bad48772cc707c44b712a
BLAKE2b-256 41c0055627e18b9fb24f509f4e170b2cf2e309b748ddd0199996c6484727541f

See more details on using hashes here.

Provenance

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