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.32.tar.gz (85.9 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.32-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.32-cp313-cp313-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.32-cp313-cp313-macosx_15_0_x86_64.whl (651.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

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

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.32-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.32-cp312-cp312-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.32-cp312-cp312-macosx_15_0_x86_64.whl (651.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.32-cp312-cp312-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.32-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.32-cp311-cp311-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.32-cp311-cp311-macosx_15_0_x86_64.whl (651.0 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.32-cp311-cp311-macosx_14_0_arm64.whl (646.3 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.32-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.32-cp310-cp310-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.32-cp310-cp310-macosx_15_0_x86_64.whl (651.0 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.32-cp310-cp310-macosx_14_0_arm64.whl (646.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.32.tar.gz
  • Upload date:
  • Size: 85.9 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.32.tar.gz
Algorithm Hash digest
SHA256 2874520348752251bdb38bd65063626caaa5732f6fd917820cb3ac08df1d774c
MD5 b18f4bc79af7ebdcbfb2a9fa4f927295
BLAKE2b-256 f9bc4dc786fd500d82640f25721d27167636c86dc1796e78fb88525c009b7e54

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f6d25baada8982640ea092defb256ab1df12bc188ca2a80cff9b1cd0a7d8a90f
MD5 4564b446c175f01f22c21f2e916e5d4a
BLAKE2b-256 b648550bd19767952702804524b8ac112f46eedddb91b547d23f782da39bd2fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 35822a15e4136ecacb7ede30b8ee1763c8dc336df47694be245c66063a8ed8fd
MD5 940b31decd3fd4cdb51cb9c9963aaf2f
BLAKE2b-256 d943f4034c049132a63001ef1fcddadcc1f61290a33a47f5b5d48539863a3d4c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 31f1db3267151bb39e7fe609a0b8320b89e7acb25467f84cb0b4c4763de5bf1a
MD5 e3d29eed6fd1811f229fe154e866a92a
BLAKE2b-256 36d114d1e007a7afd79e38f3c54adc74848cb9649a659d6a5e65e8b6cee16e24

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f4d20d723c3e52f0443c825b2873798634dd52a163fa2c9572fa31af7356d6a9
MD5 0bf168a776b4d9411ecb48bdce721e3c
BLAKE2b-256 87468b1a527679e42b7f0c8bd5d1fc60f27aea3ffca23753b17e912e6d908611

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2845187d0201e143fa9bd7edc6bd9c228500a22a9252d21ebe0f7a681bf30075
MD5 6c9931af4dd615d79da1cbb54f8670f0
BLAKE2b-256 983551ba6726b28be74443bdabac7c0ef62038fcc83259be56ec00ad379658eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1c9745ccd1ace3b99a4b0460f595f7a0cc5edc482a51574099ed54061465dea3
MD5 f3d42e4f1935818e45d3ca286333e872
BLAKE2b-256 21a287f49afbd49e0da7988b1e533e41ee8352b7f5091374a7b38790cd70ee22

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ab0aa02b1be12e9b42d98d0098acdad903bfd99eb0281cd9b4756bf60e93b4ea
MD5 b0cda2a30c7c307eb4e9496ea7164211
BLAKE2b-256 58e0b11fbdb8c3c74a76ec2b9021a8452810380578ce701046e7020857811604

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2a10050230c64842338bba10e0acf02d22f233b6be57b451e260d966f54ab8aa
MD5 dd6305c8ba1f60aa52bb66ce421ab664
BLAKE2b-256 d81a5c17453e0df08f2259bfae3cd365536c4b0f4b8d8c81d1898807b5ba5567

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 74dac6172ac047f3d041f112b9eda5e0c9adf5f643fdc0a744ca3572b63eae7e
MD5 dee23e5283bebaf2f1ca0a46eefc7693
BLAKE2b-256 d685f469168a7ab54d0f2bfcf86e21c50fd5a2a9fb1740ee31621059418c51b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 39cf6d47a9158de127f50d04248a4862d3fcfcf8417c4103d41367212077fc91
MD5 c480ca400a57168ade86f1a61589855c
BLAKE2b-256 24afdd95dfe83be9da030fdb7fc699918f15c95b03188eddbcb9be2715d2273f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b569bd01dcf72ae061ee6cf0c1a42db29f64c8b72d8062f9aae4c55d534e344d
MD5 d62e9e078b0f3449af9b6f5ea66a1f5f
BLAKE2b-256 09e9ff6816f6c4b34e9518fee97c2bbc9cc36cb6f2d5af0dd1e9f2ae3dc76448

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cdca6458a05a8ec48276f2c4f470cb3527ff0d187ab78da3762245b15f83fb52
MD5 2741b547b471d9ff3820409eec718c67
BLAKE2b-256 1c2402bbfbc0963014d8670bc972e65d921bf361eb289e2b05690f773a3ca415

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 239cbe6f26472e0d6cf67a8202d53f99a1e384cb67ddde29cfd47dc607311ffa
MD5 950f97e79239f18e50431add512750cd
BLAKE2b-256 17879e75a73077e383fb60eb03c2536c75fff3f546871c6459b903a0998c7214

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 09296cbfd016dc85f0b775afbb1158adec2323cd518f7cf8c330d93740e28cee
MD5 fae85fe5d4b33af63e7b889b2517ed28
BLAKE2b-256 a3bb4b43bb36737e44fb1af4d45ba5aab1ca3817d21a066a411d8a09907e7ca1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f82621f9936ca129a69d2290f2bd2f5a27f6c3cf036b3a7d0f01785ee932603d
MD5 f17ebc4e57802f015e0411f4c32b5445
BLAKE2b-256 cd649ca12b520d16e50f7254ae546f183d01031be61e1cfa7025359c3d65b754

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.32-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 160afbcd5999bd6436ae1271a31fd1d7bb4300b1b149d415c98b0383793d6c37
MD5 f974732f90fe49d68a223a381d3dc9b4
BLAKE2b-256 8f204eb77e81c90e897c2d11e9282f1b3e1318bad9f2e1fa2606a7e4610a7577

See more details on using hashes here.

Provenance

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