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.30.tar.gz (74.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.30-cp313-cp313-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.30-cp313-cp313-manylinux_2_28_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.30-cp313-cp313-macosx_15_0_x86_64.whl (590.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.30-cp313-cp313-macosx_14_0_arm64.whl (633.3 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.30-cp312-cp312-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.30-cp312-cp312-manylinux_2_28_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.30-cp312-cp312-macosx_15_0_x86_64.whl (590.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.30-cp312-cp312-macosx_14_0_arm64.whl (633.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.30-cp311-cp311-manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.30-cp311-cp311-manylinux_2_28_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.30-cp311-cp311-macosx_15_0_x86_64.whl (590.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.30-cp311-cp311-macosx_14_0_arm64.whl (633.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.30-cp310-cp310-manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.30-cp310-cp310-manylinux_2_28_aarch64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.30-cp310-cp310-macosx_15_0_x86_64.whl (590.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.30-cp310-cp310-macosx_14_0_arm64.whl (633.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.30.tar.gz
  • Upload date:
  • Size: 74.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.30.tar.gz
Algorithm Hash digest
SHA256 2e1c47d7b35d879c69757e66c4082e1d4ac126599d0b012d614d84e9e99c18f8
MD5 c9ffef51de8a3dc0293f77074679a943
BLAKE2b-256 21eba50d94bde85cb4d474b2676961c0696d5e950ccba8e61becc6229d344ff2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f001ac6d1b36ed245b6b7cf85a7bccf5f4ca2774333a98d1c530b3f6113d7ed
MD5 8c14376e77b96bab4bc5803d5ff5dc06
BLAKE2b-256 f60687b0603979f36545c8fd41ad6c02d950e42cf4f222d5335545d62409a7dc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1959398d9b69ca0c9795ac96b9fce2f20d325b29d698cc2264dcdc5737bdcc27
MD5 21729857ebfece61173490e42a2a2b39
BLAKE2b-256 5e372d8690f3e4c66185943b0383b963c5fdbb6a11cdbe8d396706a119a6218b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0fe1e545458b2002a61bd76701869c0af3358af814d0bee9de04e3c8ac6d49f4
MD5 e3ffb8864d65427824bfd72ef09da065
BLAKE2b-256 5f371e23ec17832c33cc5aed0c3280ac79d4b40a0fb6cb1468e058ec848a5f68

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 01912a669cbcd0e17b04b86d25a0ebee406a00316c2e043849089847ae3c4835
MD5 1e3b1d9fde1875e016680c6bd41342ae
BLAKE2b-256 e7d170ce49c944d0257e056c14a71c7f57f390f36b79ecf1d70a511efcb2717c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4e2745908b96e6d0c47b42a3ef37233730e759d33a193f79b8f86afbe29f695c
MD5 9b6304b705a8114a12b8d8e670c9ab44
BLAKE2b-256 82d6f543b2354df34d9b1a615f9977dbc037c9d27ca8c667cede8d997de7d586

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6f1ccaeef82e782331a8620f2657e6f4d6cdc432aaf68170b320f5e90f3a5141
MD5 bbb9220092de1e40987dffd5a9a15cd8
BLAKE2b-256 c3ba2c6410f4ef96a249d4106f21d8f200771cfe929cd2b7e3b9af3e3e096f82

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 2b6286243fd78d623eda81ea38d024fb896c73d5c165fefab62fd98f59d68dd3
MD5 db4d2cc1f2a65bbf7d0216ccfbdb41cc
BLAKE2b-256 d1069e386a285bb951d0e700add09ea0e136daa0db21ec9779619e248c69170f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f1ae42de04663d07deebbc7a3e3d15e54f2ad1bdce46dfe9373446b79118f2f5
MD5 56bef69af50c61d5d64762bb535d9587
BLAKE2b-256 4cc1dc14d6350372efc82b0d076fcc3cf7e808284f7f212618c403a7c0c3fec2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c4f02f9809700c19c36a8b6fa3c04c54f7b22f2fe10b69ba18e499ba8cd83abf
MD5 c1c75d30e38829291e4e0950b23f2a68
BLAKE2b-256 9792e14fa54aaa191098bcd8d7f701586076e403cf47f2b22c296310c5d81576

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 20e836d607a6c0ffea33e58a1a760fa5d65c4110134999c3d17a7d70181a76be
MD5 b5125578b2e7cb90e38d462c978aca30
BLAKE2b-256 90229b52c37e7c72b4275a6ad9f5876a7b496f34dfcd4dd07fcbbb8a0a655e02

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8d4ff9061c5420c28ca9f07aef0e5a869639d9b134d76889a77a6d0ae902f576
MD5 78bc26eaa654546e27d20956ba52f88c
BLAKE2b-256 d2cd268ad9db6064baa1ecb95c8ead06dbf5380804abbde326fe256cb6f5b715

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e7011abba46a9cedf3e51ffecbad3cf067413f240376444cead06273fea3c7e6
MD5 bc06b28cc6b638920db00c6b4e7dc8ca
BLAKE2b-256 a9e29d9415365623a9f5f3dd8cb50d9dbb3896351e3788ad4a0f389990626767

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c73890b1253b6896943471628c855efe373ed843be8647a3bdefff17cb4a814a
MD5 b0f736144fc93e9440053070910ca01e
BLAKE2b-256 56981c1526e2c6e22b3d5b8c23c2a29813cd1aba26b433a3ffbeb22142dd2fe9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2da5b952b62a2e2b522dab5c4d9f84042cfd5452bc4168071d12f419002941fd
MD5 420897dc6f742b76b7f9546d5b279fb5
BLAKE2b-256 765aea82f29ed5901dc49c1dadeb4cd9513995cc44d36c0919501a69cefb1b47

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 194c6277484ac94145c5cd83e38d60ab18eeba7e7960e632019cc4a7747de697
MD5 f666e84de2ef1372dd19fcdd1e333fc4
BLAKE2b-256 8879e59cd77232c3e26885ba904987f3618edd6ea7bcc1d9851956a31749d926

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.30-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5c93a53dadd42f9dfc71212bdba7717f87e90b5bd8fce1c377adf8403841aa92
MD5 69c0541fb32bd91cd5ccd86ed08d44ca
BLAKE2b-256 267253b81367d8419535e52d324717cb38faef61a5973f7160f9977593c3f1c5

See more details on using hashes here.

Provenance

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