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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.71-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.71-cp313-cp313-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.71-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.71-cp312-cp312-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.71-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.71-cp311-cp311-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.71-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.71-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.71.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.71.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.71.tar.gz
Algorithm Hash digest
SHA256 b083f2764da2532e88b3dee326278377ce319b58c0f12ecdafdfe754f2a63e1a
MD5 8d2a316f5ac6930a9f10e5727a0d94d0
BLAKE2b-256 e03f1fa30f514dc88125a0b773e2e72809c9ac59d2b187695e0f4da006688ad6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4ee2130a3097ce884d1738d3c4ac054300bf522e8cd8699fb6898810547b6976
MD5 995d845e7b7ee2940bfaac67d1f89ede
BLAKE2b-256 80562f9bc1e37c186874e705a0f511cb3a0f49d0f837c7bf76232cd3ae27b970

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a5ce8e8aa7b4cfb85228b3d21f1a19197e03ec7eca0d3339de8eac54171d3645
MD5 f740255bdfc85aad361ddac751978851
BLAKE2b-256 53b214caface78cd89826f7d008b5ba2f31b31cfec77fe4e7c64a55c4445b000

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 685507ca0898db8b1e4e4e432043999cfc6b67ae8ec2aed4f8922aa94a8ac420
MD5 3ff76597d9df4bbfe1d4eb1a392d5c6c
BLAKE2b-256 20cfde1d3f43ae687e7b20780828b5215838608da9d5ebaac1baff8c463c9431

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f10d0c2192dd34bfb8210b108c4ccb4b40ca3dd957ea3f23dac37871537cf605
MD5 6fac6664cf4f167002bb1ade9ebd2890
BLAKE2b-256 3889f8d58f7a1b7942c89527d8fb782f121b629751eef91d8ba69a94292396f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2d603a11b6de05e2e2cca5d173f69cd124557183c7993194481e6391b068eda
MD5 a0b808633baa07ecebf1f1e428fd1e5f
BLAKE2b-256 e4b1cfa3370fbdac41df514b8445c8dfa49ebf9a35dff387d398d415a1f64bba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 adec8b805afa3241410f9ceb9eadebf89e9d24415e28e434cbc5ba5c0b9e587c
MD5 99ced0f86d2299d56ddf87c3e96464bc
BLAKE2b-256 7babb3273c58ba650d5f2e2b2690cf6530bac88e38202082838fba39afc2ab91

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c8bce8bec23d03e1c463136fe7a7d4464aeddcffa9beab174fabba162e1bb7b6
MD5 0d18bd9abf2ef05d881c832b60d5f1a8
BLAKE2b-256 c4ae629277837fdd8a5c3d26c0bc726f56b29c68b5824a6134993f3b2bcf29ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1743cf3ecf82428d3203369c70c1e7db69d18a05db4ae61403dd060e02f1a2e
MD5 bf3d8513e2d8744ec2e8e6e037e974a2
BLAKE2b-256 d1270bdb83175094c66e5624202b75478c5ad4794e45b5d8542bcd893b89d188

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 93e54168ad4d846bc3c8600fa2cc67ddbd2e7ea8dd1e856bbb868fe8330a8936
MD5 b8c9e7f5242e65c5964b3ae109fba24e
BLAKE2b-256 fb110a1a3c627ff99918d04fe507cf19c5a4ea3bd040b0f3f837577eda746fe7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 90fff4d89b77cc8c62ad868eb6d8c928dda76e5a76d966519663cef69a9b7f92
MD5 18e8db3816846ad924d4bf3d9071f9f4
BLAKE2b-256 6161eeecf23bb3d83d09ab3ecd4c583f2ae4c5ef82dc3e68a41b97a11a9d371e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c6f326c8e6cde980d6acfb0edab85f06d7075a6567b46d25ff347ac3915e9e2c
MD5 fe86af309bc1100fe41bfca1df8ffe10
BLAKE2b-256 ad36598d3b904dd1177ef591dcac6dbbfb8f8e38c220dd14a92a5e6f1e3988cd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e2074bb88ad63559df62e0f1d6d0f524c725464d17a93033b4fa6f3bd9c27e83
MD5 e0168715bd32d271162b9648c52d973b
BLAKE2b-256 6836ab71b3ce7cfffef12b5e78c447cf23886c38a14b1d1a173849e593514256

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 436b79f41042a72ca845da1fcd22a31c3f6276307d6f0d4c654ba33b33718f4c
MD5 1b9fbc2879670220a6473bfdda2e2c10
BLAKE2b-256 8b985b14e857140eac9a8920401483dd31dd821e6f9cf1835a1fd49739dbf630

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a2e224088f7eeb30dc153e67fa82ba4fc71826f398b8e7e0a2782a985e06d0af
MD5 138620afe2c94222f553ba6d8ecad593
BLAKE2b-256 f031d75ddfe82ce24575d289e37a93432d69eeb143a1d0adfe40e1dd2bcc4b87

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 27ea9e8b98504350d7a0851103331a73ffb9e1a6331cdf0ee34944782e0d4383
MD5 8d7dca5f45aa0852d504cb1c5b1763ad
BLAKE2b-256 56e1fd0729844cb342f20190e6da55ff0447dd309fb58195ca952d514cb4c66a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.71-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 240b2c3b81d40b62b4e72b57d4ad05f924447028801ba682fa68eefee76c0a96
MD5 6a2c053bbab06cd948146837780d01b4
BLAKE2b-256 130804f9c408f42e7bcf77e3cb5cd243a5a4dcdd336d868514c1d6debb8c0336

See more details on using hashes here.

Provenance

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