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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.70-cp313-cp313-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.70-cp313-cp313-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.70-cp312-cp312-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.70-cp312-cp312-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.70-cp311-cp311-macosx_15_0_x86_64.whl (664.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.70-cp311-cp311-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.70-cp310-cp310-macosx_15_0_x86_64.whl (664.7 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.70-cp310-cp310-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.70.tar.gz
  • Upload date:
  • Size: 92.4 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.70.tar.gz
Algorithm Hash digest
SHA256 f53ecd11f57ca8ed9d2593df6ea4a346e9331a75e56fe6c22b11a1c6aac968f0
MD5 11b249883ccf1f484a56a663acc72596
BLAKE2b-256 abfd854fd4528c5fba5e226b6e1565c57a966083e40851622afca34f66a7b78c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b04c90ad42e2331aca7732207befe51311009bb28c8354ebca3654774a36e444
MD5 b24cfb92708573150975ccf183e002fc
BLAKE2b-256 bbbbc439a4a87dff57048542d7d3cf0b35cc8c7e692e1567240aa67662a87b81

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0b9dcd5c0e674275e96b9eb8c3e59d56d4087218b97f3e2768b51b71acd96499
MD5 78c5be71341dc2c94e8ecba332813c3e
BLAKE2b-256 4ee5011735b854edadda3cb89b6cdf1bae0e5d123835025e9e8a15f47f332a95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 496f0c1ce484b18792219985109cfc7577418838d19486034d7629c160b75366
MD5 f44cfa3fad76265e6998dca36a5f4355
BLAKE2b-256 69452a5eb523ed794793901e59b1a99da692e6fcc5fd037e887e794768270e0a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dc764dc29b39a2c6569905caed2528e49bc4af8c15413559d2133db013c58dce
MD5 568fefc8cf5230dc476e3383fadb11d8
BLAKE2b-256 942c988dbc0d6a5dc66d9f2eb3480ebda92d29bb02651a070ded4630c29e45e5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ee6361a7bd71c32322d91d65924b7cf52df0e9d153b66197edeff2979ce3b58
MD5 7475d55eaa19a9a403043eca6b23b375
BLAKE2b-256 28f20d4bace179607d65ba89b618959824f2fffb789f22c07a2f1f60abd29bcb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f9eebe335e16818b17ed1c215ac6ff1d3a065670bb3ce55849a90865c1eed6a6
MD5 5cc75113255655fd37fbe54368092898
BLAKE2b-256 4a6fa1bb1e4c73687ef4e7f75da6d98a2b8a70cc51b90bfb8e816caa5072ccaf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f60bd81b1fff1f32481a26dee189e6c5bef2d0c3766963dac9fa92d5b59a4eed
MD5 cb5058981dbac075dbd4d4cb79cc91d2
BLAKE2b-256 3a7e2377f83f2014b7208793e9d6d40f1b32f6bd31f428265951a7b143813ef4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e159992705e4920438b77d32a8a761dc4454561be19ad6f649cbfab50cefca72
MD5 7c3f6df61ff01b2fb9bc5acf5196d83c
BLAKE2b-256 f0c788807ec1d6e93d760f30b381b01a424efabfd478c28da8aec0989d045b90

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 01eecd9843779f2df5d9700d989be34bd3306ec0323272e13e690d30b5c95158
MD5 9f0b8f7227c3c799ae36cd25c082038a
BLAKE2b-256 e675195c3eda4cf4dc652ef593c7b79c92ff7f18afff8aae13b8d3537d92f1ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b4ab2cd688837c9875c99f3f6b669e6e92666be18d7689acf5a63da8ba5e38f3
MD5 060fc0451f10db1c7840b09f4b5a1f96
BLAKE2b-256 dc5de69e7f992c91015eefff468192adffed8c470fd9264e01d497d4f7d8df2b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 626f4c8773e968210bf6e47ad1d0b0371bbc6f73b10e12d007aea29d33b62036
MD5 57beb7670e520595190d02d8eab71966
BLAKE2b-256 3e9a5347093134895abc773aa76498b13a496d0acf1d0ed59216312e31b374f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 93bbccb75fa0bb69adab8d80037b9f3e340aaa4878487cdf9bc5d94720b1a939
MD5 6d0de5dcabbcb57ec74277601db6cdc1
BLAKE2b-256 e38b960b7bb0533d4e94b0d27c23a7eb3b49e64456cb52bb771887fbc54ea7b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d9394b7e2f5c1ffe4e4f41a486777745780aecfb70d6ec6768d4589ce047432
MD5 05bae28bb743525072c66b579095d95c
BLAKE2b-256 fdd15f0d53e96584a065fd44e606191439fb5a7a80377cf695aa10b3e4049a1b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0a4821d770bb90c456902439c4d776b69f0ba3e336d607a569d2d99e5a9e752f
MD5 4fdea0eb43c150d68dcdad6cf69a6c3e
BLAKE2b-256 4c1f93cbe46398e6f90ecc5fb43d97fa6ec9262bba163ea6164e916db716a053

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 52fcb3a53e2b88b2a33947acb68f6e67cc044e243ba5c7e66fb2721e8daafb50
MD5 c96d11cfec301b6a5e680ed44c05fe56
BLAKE2b-256 d370101eebaf570d6eaffe4ee0a260a3ded671fc0e1f4c8df85b85e4397b65dc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.70-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 19ff88f8f87905072a52225d1cb30c07707d3816488e1564fbe476dcecb9fbb8
MD5 534ac5de78cf39c68b0a2de43ba479b9
BLAKE2b-256 54849b8c1cbff25a825982f302f2051206b2bc5d276d27f7d0698959ca2c4473

See more details on using hashes here.

Provenance

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