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.45.tar.gz (90.6 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.45-cp313-cp313-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.45-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.45-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.45-cp313-cp313-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.45-cp312-cp312-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.45-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.45-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.45-cp312-cp312-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.45-cp311-cp311-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.45-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.45-cp311-cp311-macosx_15_0_x86_64.whl (664.4 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.45-cp311-cp311-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.45-cp310-cp310-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.45-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.45-cp310-cp310-macosx_15_0_x86_64.whl (664.4 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.45-cp310-cp310-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.45.tar.gz
  • Upload date:
  • Size: 90.6 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.45.tar.gz
Algorithm Hash digest
SHA256 d8b026acdb3dbb573d1f4ddd49db9bae7df58b85e9de1303930a77326d9642c9
MD5 48e4b9ed3440cba52ab477bf77073bb2
BLAKE2b-256 02f41950faddaebaf7169645c079d5cc138f539925ea1637130b4ae6dbba1569

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de48642042967ef43e370a49cf2813632c670c95a8e37febfff94b0c8ec97429
MD5 1a4b00a13b46f9c4fa332b4610aa6c6b
BLAKE2b-256 abc24c9a3daa111855e8d2bee01b63338c048c3eb15d1d728cd723f7ca68b1cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4d8f8965508652263699ecc151918246babf46f916c9a9c93f4890bb3e6b9e79
MD5 b7aac79d8108fc88d5cbf0b252a25339
BLAKE2b-256 b118bde7077de63c4f610b7bdf70380b0ba06cba9516de67b64ea09f77d4c789

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1dab24e0a572a8563f9f667bac9998b0f1eee06e5fb92327fdcb47c808d3a95c
MD5 db5a9f98f2cd430ecfe50529d793cf6a
BLAKE2b-256 0a3c876cdd20f96303462323065333edfce8a6cd595df5b102155f912e63b354

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 01278b5509f8169ee051b61706dcbd5e3d842746951aae01e44c37e39dfdd043
MD5 ffb403a82bf9c838b10f62b9689e83ac
BLAKE2b-256 8782254ff9929edc20c7687439619650fc33c695fc2a8b51b1a440bf69f0b160

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 08f0d25fd323126e4b373fe608c835e965fc36aa5f4f82fc59cf75fe5bb3f24b
MD5 0b252eae6f9a6065b015465fef207a7f
BLAKE2b-256 253339b90f0b16560ac1f350ac49c1a5592e79ff732fe29774fc8739e8e0e8ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 69839eff98c8f71dc5a71e9e0601ad6ee10caae9e6b283bac51ed3c346717896
MD5 ede4b1899019366a727505cf3c1a7f2d
BLAKE2b-256 146d2a162b4eafc6e1b9de2370a7925e97c3090d7087ad7d333b7c6aad094efd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 36a03929da9e31b1f85baf1d4722bd328a15f891b1cd310860a5b0ad605616ce
MD5 d7de6b18a1a386416a5a450781130cc9
BLAKE2b-256 496bd57e5631f0976cec5c572d309c4a32062dfcd0f435a05301950655c0681a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f1bcc155f4320e0f2d58f95d99505aabc41574c449ff7fa1794de1e60bcf3c37
MD5 e68f65b4fa208c24b562ed1ca3d3be85
BLAKE2b-256 06fa400fef0ccb10e4fb0e66d46b23aa06ffa24fc4c802462af47d278ff39ac0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 353468806324a92061b0af2787a8d26587ebf812f613161cc534cae98dce898e
MD5 514d431e50cd2f8b78216ce49635d83e
BLAKE2b-256 3cf951bdf87a9db7c2ba6ae982db9edaf071e7b641607dc903e95a4bc579304a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c2884fe8fda35162c840759069d546e53dc12aef79e9801aefc89eba1a20491e
MD5 6db39aef1deb94cfc1da8365ef54cd5f
BLAKE2b-256 4134d30f277d3f9098d14f0f798db260857d959774c5a07c24942fec7e9dd1af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 13fdd9bd9906129dad98b9a65a75cd28776a6d5f06ee58d93cf7b53016d98c38
MD5 10e6979a246688b0a9bf27dde8f56913
BLAKE2b-256 7dfea8d623c27b5b85cebb82da02b687569ff4879512a9143b68bd62c462c177

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2414c3be6830d2f9d18fa27487d5f3afc169ed93979859c9d8c555c72f748e7e
MD5 0bc248ed0def8afdaba58ab0e0135f5d
BLAKE2b-256 b0666cd57cf9d96cb73918eda5d7b9ca2615da9726d66872dcb6dbe74348ad28

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c3f30b10ab50f451834d8403d2c4f0533d482f069c5bbe5d45d31214106af241
MD5 c2de61abd0622fce9bb4a6fa26fbbf8a
BLAKE2b-256 3f86909e83819a2a1561722d6efdd796051a46d9d93536dfed777266a7c88e37

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dbd577d98ef84087e93c4612de4faad05b66ee09e9e1e4388c70205a306773ba
MD5 aa0e6c8cb2620b85c3a898ddbbc7f97f
BLAKE2b-256 60dd44445c2c9aa9946c51db2c77f1175893de34f42cbc034665a97edaf8ed6a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 dbc51bee91ab2c211f45c4f7074e813ae7b3f085bc3fc4779f050e31a4dc0a9c
MD5 df81eb20db18363dffe898abf563c35d
BLAKE2b-256 5882cf3fae84fbb30051403263265abd9e9592ffbd2bc7521e4a47830fb80583

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.45-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 80a44aa115d6ab00c8b477814fd7630ca06d77a9fd391919dfd2952c3f767a10
MD5 598563d3918fd48a1eb24ec12d80b00c
BLAKE2b-256 fd1c4c327ae4da16b6d8e95da2963e9d65d51883ea8174e9a5f00879998ac14d

See more details on using hashes here.

Provenance

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