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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.52-cp313-cp313-macosx_15_0_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.52-cp313-cp313-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.52-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.52-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.52-cp312-cp312-macosx_15_0_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.52-cp312-cp312-macosx_14_0_arm64.whl (663.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.52-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.52-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.52-cp311-cp311-macosx_15_0_x86_64.whl (665.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.52-cp311-cp311-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.52-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.52-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.52-cp310-cp310-macosx_15_0_x86_64.whl (665.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.52-cp310-cp310-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.52.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.52.tar.gz
Algorithm Hash digest
SHA256 7d9a0ffb85257f62d8e39f23a03f0da4040250a96bc06218e8bd94f313d7ddcd
MD5 a48c805db50119100d6ed15daa5db2c0
BLAKE2b-256 7fb1990bd3edb7568dd0b0c20ac15c7b1ea1c557ec6909227e1e7a506e59b423

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 956b8f102f07152d5c9247825b0968c944590c46f18988e773f093408dd40b32
MD5 05bc4b3c6d14ef0459cf2ec632b110b0
BLAKE2b-256 6f486a31ea04ada6e4dc4270ffbb0021be7c8ae1ca2248903387273cbd984dff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d10ee49b6f7cf53136cdeaef7ae7c7fa9b0e7c3a78f562f8517e7f82a41f7ab0
MD5 cab03266c649c0f57bb68545d2ba0720
BLAKE2b-256 3aa6e10ff32b49e80abeb88b5cbaf205ce418b35e57cfe26e3180defdacaf521

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 cdab74eba748d65644cb8ee26dd4d46e08ce1a26a804b6641fcaee4e91168631
MD5 d10a926b0f15ce675607587eae5aef05
BLAKE2b-256 3f71e512225a0a696ad6d3f66542feb467a6c761ad74cffb4a2fadae24d05418

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0177f4c8fb6a7b11c5cffb7efec412f7812260c3dc5d078e84671eb7cfd9eed9
MD5 0979e0b44b148bb2581fb958f7c8b82b
BLAKE2b-256 d52131d80932723adf8bea20d496be3563b90e7e2b46d2da6703946f6ee2e5e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a5858e15ab12ff0b7bb97a7c28e29634d603a5b4753058e294b8957517767c3f
MD5 1d538b36c1f910d65a9fd5dfc7cdd10e
BLAKE2b-256 9f5b3bacda55a7d533b413c9f7a0b67b97df700f1aaa1f51bae8d5425d05fa5f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 208a90cbb813a111b6152df068dd804e3c48b36ad811b1e4606130eb18801ff9
MD5 c0947c58a46c975e69bbd1f814998f9c
BLAKE2b-256 e2fda3cd665e4b70806d5f02896fa4ec578d9f7dacfc241dc2b765a6e9f76676

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 af9c36ca5fe6782e8b541dac4a057c6eef9b4486729e48b5c3a76b34900a7b1d
MD5 f2863faed4d3b8798a5c64c776e6e952
BLAKE2b-256 6e6eab1a9ce7a88f66f3cbf4fde4c3e7255a92c4b1a2e89c1ab017cbfdea6a95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 98d133d14584d430e6aaaf7dae094a84fb1ebf5768781f3b9ddac49afe7d22a1
MD5 756086023607a32fd2c7358420832953
BLAKE2b-256 ee90cd15e1e8d2824d962d3f1f98d54578f6917c29380877c6e1bdc26e6adc94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b2a65e7b9a9eeca7b02eacc8e8454d40fbde5991b023c1a9f6820caa65361222
MD5 3a7445b61a5f3cf0da8ff76c4dfa4069
BLAKE2b-256 b5e03886a5c5be84475a29f2e955a67408e2e1c9a986411a96426aa45c02d67f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4c4effd953513274758d4eb3f16cdb0a13df3d6fe13dd3e5cd673c9a7d57bcca
MD5 e5b03a327e911f498e2da44b86364aaf
BLAKE2b-256 4ed710c67840a2c86db78598a2386c64aaee3a033ee7165372c6a1ac963bdf5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 77044c99efa529fe97c102e9f27bc61f39d016039c4a44cbd7e9a87c679819fb
MD5 7ba1140aa9275a9e0631f5492d16e107
BLAKE2b-256 58bf311f109aab98c0b59d27b05a7b95b60afd496bdc1f80ce99757cd506d04a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e764e37fff11fc15866fd05e536692d266920ba707e84f95a3a9577149894a01
MD5 2b3b34db8db65f1860d92db060ae9a07
BLAKE2b-256 7019c691600aa761f684a1fed6fce3674ffc691b7575771b5b8f0fe2ce9933ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f37e57749e32c78d870ca2b65fdbdfca72223ceac8c4dd9695921e8933d819fb
MD5 3a13e8611641648b4271d36757f6f955
BLAKE2b-256 2e7da14d013833d4ae7c743f60b5f206f6c2153443a8c4d188e79d64dbe3140e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a93e5ccb04a50f7ebcb33f2fdd5d91f83abfa9750a3b21195ed358bcf3bf0d06
MD5 46a9be2cb09f7050363503d7e615f58e
BLAKE2b-256 d10e32295c1e6548dafa4fd978865b1d0683dfccd7402264728f8759b6f19a08

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a072da06620ecbf1ad77aaa1a8f04d3f860dc222b0282932aa891e3e38711cec
MD5 d47035e536a0ce0634f0fe91817ae560
BLAKE2b-256 9bf89e601841812833d0feb014e83b1f7d2d83df10a5279ec5032c517bef4205

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.52-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 326f25fc8d612694ffeb1d0ca34d9eb9939df281197cb27773dbbe4ca2310460
MD5 575e6c60b048ad87c18b9793c649b78e
BLAKE2b-256 2c474b2ce27f935ebdb642faea00f7037665bbbd68fdff57ee7c505765748066

See more details on using hashes here.

Provenance

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