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.66.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.66-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.66-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.66-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.66-cp313-cp313-macosx_14_0_arm64.whl (654.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.66-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.66-cp312-cp312-macosx_14_0_arm64.whl (654.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.66-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.66-cp311-cp311-macosx_14_0_arm64.whl (654.3 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.66-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.66-cp310-cp310-macosx_14_0_arm64.whl (654.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.66.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.66.tar.gz
Algorithm Hash digest
SHA256 863ed5028647f505403954a4df11cc193e268cb40af7e66bd1f93414d6260d64
MD5 357cbd035386ecdfdc4b4647eddf26bf
BLAKE2b-256 aebaf8a401c758392089fc0b8d6f7745a725c98231808f0a6d98be2560f03637

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bd7ad14dc89e2227192741d7d9449b8eeaf131fdf8bc2ac5b80a28b20faf58e6
MD5 dc038d07f70f79f4f27b1bde60bb21fd
BLAKE2b-256 3b8e3df1120a8354e7b5b4bbcb8cb5234261e6c4ee36b98c8d0162cf0cecf05e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e9460f51145899b89a453a6d6cb796956f066c887cb712bf89ade8cfbe698751
MD5 cf4d5597a685dc164ef9de3dc906849d
BLAKE2b-256 027cf130f6c8afaefd8be7342de1de876f026a0eea9e455b37d4df82b5122eca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 36941496ef11512c6c5e51b68d1f61d8664fce1beb565e024bdca412c6fe7468
MD5 7635b44e3b15b99c72278de477b0d655
BLAKE2b-256 bf949a7b586aababfe0d1b7b3abb06dfab922ff1200bdfa821545ec258f555dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c3b8a182cea4c4f471a6c1b2d602f0f496168df56503cdc876f06bb95319fc53
MD5 5d5ec6bfb6561537969cec5da8f91da9
BLAKE2b-256 6a81000810b2a080aaa72b0ab02cc9913d6ce9c436920fe70c557489b47eaaef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b52a755466e697f3b6865ccc9bb9943852222afb303652d2176868c4b7036a5
MD5 885613485be09e8fbe5cb2ccb224053e
BLAKE2b-256 563ac43c4972a2a8b9588d7a9afc3dcf882506d053f045ba1503151c4a14cd9e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7359e8892cd1044a1207b6a9914a56411e1b9eda0cd335656d0a6eed776ada87
MD5 fb4e14950f5a78aac5d70342e62c0f78
BLAKE2b-256 1c28fccc5f92e95724b12c93a632c0f3d2bc37cd483c2389bac1e2fbab3c3e94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 76a6246dc0b9d4b75965a1e15ba926bddb83b7cae297f4c567df00432c53def8
MD5 5d9bab15939f8cd7abfd04e38fd0c0c5
BLAKE2b-256 123f2f50b3cfe0e97683eddbe6d960970e5989bc43bf45ded2f581551e3ced36

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a45c49d831d3dadbb0d9d4f0617289d16315632632ec292d4740ea406890a080
MD5 093f92b6f31b76187863a275b3fbfaf9
BLAKE2b-256 0a94802702c60418f5b3181624018532c8310bebc1da42a3919d420a07f0dcd5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 859a4dfb8382f900857e0ca2836a32ab5bdd4773cb2d6b91139422907e3b5f1b
MD5 1e3bb7eeaf16f9c1783ea5cb1334e853
BLAKE2b-256 228299ceaa15d61e4690b58fb734dfe729877230aed4fec5757d15b2148873e3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9dca3023707d3d7ecfcc0ec136cad7683f96c7daef0cbf0e5c3720df4f3fe1d5
MD5 e45ccbaf5e1a1eed6f93223c71bac63f
BLAKE2b-256 30c03e39cce3bc70c7da147fcbe0906cbfc5af9128c3b633898211e576edb958

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 db03e6164ad7a33912fa4dae0dc9528fc86b255927181cf644338ce78dbf9331
MD5 0e6e73479a05bb4ca9d9c900792f451b
BLAKE2b-256 5dbeaba28913ac69d8289c73fbe31e98ff817f8e2a8d13364aa81746c37e104f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aa878a0de28cb0b210e1e26758573916f9e3a96154dab9df433e4be3197f4a79
MD5 757318f89b0b1885a36df697a207e16d
BLAKE2b-256 d784ae76bb6b86865b14794c44bd35b0f62076cf29e22e2374c07ef9ab81eef2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f9734584dd5fe578dd76ea03c9e858dc30279364b3385e5eef92ecc77b7285d9
MD5 0e16d35a00adf651cfe9a4e7987a1165
BLAKE2b-256 6d441effa430124ca105002891af5cac232b87eba417029ee2435a704af6695c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e5bb13638a7a4a2c8ba4b2febe8ded152c6c46b0c2d175d71005167e327c79ea
MD5 9787e27a128ec3e9a0429283e521ce4e
BLAKE2b-256 058e3858ed398eeabe4e111161c0c9bf83bf7195f930e636c7490516b72ac4cc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7b794039210deef77c4ffa23fd90c708cd01fe6586942acde1ce14e62de2eb9e
MD5 6520ee965aeb7b0efb445fd4fc639796
BLAKE2b-256 3c44eaa60a9ed6bf7765175877d9b393aaf41c1b8364c46bb38adb2f03a02cb2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.66-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0f2b739dae365c9ad0495bc423c6b95054f1afff38fa1fe78a8a8df67bedcf50
MD5 51b1d57d8412d0c0485c832d47edbfea
BLAKE2b-256 5e46388b83e38c557b466e5970f75db5f079ea487a492057466f0b33c804f963

See more details on using hashes here.

Provenance

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