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.37.tar.gz (86.1 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.37-cp313-cp313-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.37-cp313-cp313-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.37-cp313-cp313-macosx_15_0_x86_64.whl (652.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.37-cp313-cp313-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.37-cp312-cp312-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.37-cp312-cp312-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.37-cp312-cp312-macosx_15_0_x86_64.whl (652.1 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.37-cp312-cp312-macosx_14_0_arm64.whl (646.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.37-cp311-cp311-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.37-cp311-cp311-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.37-cp311-cp311-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.37-cp311-cp311-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.37-cp310-cp310-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.37-cp310-cp310-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.37-cp310-cp310-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.37-cp310-cp310-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.37.tar.gz
  • Upload date:
  • Size: 86.1 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.37.tar.gz
Algorithm Hash digest
SHA256 da48ef36e643c5f90120284d31e5bb2113189f6e37a37fd4ed35a686dbc194d3
MD5 f26ad5d8ee250e1c92e6d0c85590532e
BLAKE2b-256 7801a96340d3019a80777415059bb5f88b3e703b881cfe0402e2b54e70eff890

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7ace121fd8f3afe1c4ac81a7d832b17c6a42aa04c52eea94103446ddc98cbf07
MD5 b4d6e3b4ec62e86a92b046ed3a31e028
BLAKE2b-256 59a2bdbf39a02c4b97f57186052a91292c8537b3b9908f1aa194748d6fd1591c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1158cdef45b3a33819b673fb959dfaca27409b4c4a4e533e5e7ef47114df6694
MD5 45b3dbd8e08f462f3fe6e5e0ecb11437
BLAKE2b-256 cc8221562d1ca4bed49cdd4456ec742007aa67dfbcce0cefe956eb0f325ef27d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1d8ed0bf43379963e4d62ea27fa497d337b20b80bf7794349739377278555e20
MD5 9a3fbba52e489458e359a8c5e4c1ba79
BLAKE2b-256 4f13cf8b1a294bb4aff8ce182841ddc6e96d27ea8e43e6882bd11522031d7794

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f736908cebbce30474d24543efb585a13ba1d356fe0baf424930213e99e98c60
MD5 4dcb21b430e226faa6c6cdc221f9989d
BLAKE2b-256 5e0c606150e65c8250e0e8fec9bb3de2dbf5f6b96bc03deeeb4dbbe34e52efbb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b49028b2dbb978a6dde8cc125ce9a53f5aa264ad25a34aeca7f4d85fe8f149b
MD5 ff27a7997d4d8cec1e94bffc45d84a1c
BLAKE2b-256 1763b8f927a78b97b7a57f0a5585c096061d8c60e50ce4ce2576f03d6c655392

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dd1e7b18fba52b49ec654757e723638214e61cfa1ce3ab78fc1ae6ba33cb4317
MD5 4ecf105102d75759ba88edac3797e90d
BLAKE2b-256 6ffde4ea4fc8b399c0ac86a7e39cb3a0538b84d8166ee962bf05ae47628a5cfc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6a2298ba24edab995f403a566c5df7f76f3b9b7d5c8f12ae72a682e5e07390a5
MD5 1e84d28a4e2a7e56866980647a2d6833
BLAKE2b-256 b7aad46fc1ead875c6036af6ede3259a5a08e6ca9c86335bd50f5b38b4a6a978

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aabeefea6950779ae36196d70d12020385f305866368ffef486b10ecddc3ebc3
MD5 c39aed311d9c4e6dcacc79f0d9cc93bd
BLAKE2b-256 6c6528575d08d96c7b7630e757d96d3821a1c6d4ef112a437dd8c3547fb0b976

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ddb79324b5f9d83dd7c091adf365870748963362eb625dc3e2f9c526dac4605f
MD5 0640402e04f45745179632917565ef3e
BLAKE2b-256 488ed69396ed613c45b5b208d66afd9364ee4b7bd25576a7a92870bbdf4da679

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 493985310fc857d43a8bc92830c9c293deec828d8e44895a310234f1f5f15760
MD5 1ab188b98774d8dd4a78443960c2fc7d
BLAKE2b-256 8c6221f046041e73a80c41b011ccfb23988419ed8955f2c693e5ebe65be2e7f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0bc271107498a5009acd33f5a0e8bcafde2b0a985d4df106a3cda16996312712
MD5 765e84633965ec9f8ab9d2003100f709
BLAKE2b-256 d34f77d1841ad2d34f5361c4260755a79499252f37837ceb13e10aecd4e51458

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 baa4a69b61bb1cfdd381ef6b5a30ff239edd9d1597a1fa72b9c6b16c939816c4
MD5 1d94ae284089b298390753045051009d
BLAKE2b-256 2239a569a350f642dcf2daff8f56b8d40c58d8c0f884208800d14c2154faf7ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4f28c553629f51be3685ee1b6c1d25a4b26e9f8cda6e12ccebde656555549ae5
MD5 978d19128a3836d74ec32b346d5375ac
BLAKE2b-256 546cc9c4d50c1ae59f28c4fe69d0364f5e658516f6e74116fc0b4c30d184881f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ddb4f4bacefe2b2070765811ffc7acf112df4d8e3ec4fea1110cd26f89d7d1c4
MD5 fd8da0564a71dfc37292812a15c22704
BLAKE2b-256 6297a366c958d3932ebab222fb313733071476486076a77c377237a945c89e01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9f6fa269aa4bc285804584bdb556dfcfbd6c1a5bf6d3cac09dc361101b49de72
MD5 4aa06ee838e9c46b9222e15afcaf854a
BLAKE2b-256 4d90c9a7a049ff7b55ec638a65f9eff22739961e24643f9f930768dc0c4970a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.37-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2f429c6a7ffd12cf48ce4f49a003bdf5fb7876a5c6eab38955a26c9574df42ce
MD5 a4a5c6c8caf467b5f264b9d4be9573a3
BLAKE2b-256 4b8866dd084a1b910f11f3292f8ca99b66f6720b950dbc377bf373a66cac7349

See more details on using hashes here.

Provenance

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