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.16.tar.gz (69.3 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.16-cp313-cp313-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.16-cp313-cp313-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.16-cp313-cp313-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.16-cp313-cp313-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.16-cp312-cp312-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.16-cp312-cp312-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.16-cp312-cp312-macosx_15_0_x86_64.whl (568.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.16-cp312-cp312-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.16-cp311-cp311-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.16-cp311-cp311-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.16-cp311-cp311-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.16-cp311-cp311-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.16-cp310-cp310-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.16-cp310-cp310-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.16-cp310-cp310-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.16-cp310-cp310-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.16.tar.gz
  • Upload date:
  • Size: 69.3 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.16.tar.gz
Algorithm Hash digest
SHA256 b379e499d4b322b7d901405c278a9b8edf1de2cfc0ef98cf2cde3fe1161643bb
MD5 237068ee5d6cad8e4fde947d3d04baa3
BLAKE2b-256 70df2d73fc431393362913db15d8af83d96427b6b295355609ddb57cc1c95003

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 184cd0aa2c64aac14237410e69ffd92d479146c9f9fe749b378691ade3e6f4a7
MD5 fa14907b4667830c437dc8d58857ccdd
BLAKE2b-256 c1949b7774c485e732d1616eb458426e6569490d31cc9f9c701fa8ac06963b09

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8877887f60c84b1ed41200a7e5e7f10ff720869cf4ad7a7a9820436f54cd21c9
MD5 24683a270ce10193322dcb7422c93de0
BLAKE2b-256 5e38a510fd3bfe48ac100072d8abad3badb29d3afe77b29e1d929f98fdc76b04

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 89eda9ce66784a176d1124292f87c87ed5ebf3b3f277f48b483234ad2a31ead7
MD5 7abecd6e7d1c71ad9a7fc9d926193646
BLAKE2b-256 fd457931220579d7d7d57227f2527db38b9785ac26269bcf37a763fa6d444ca6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 cdf5785a14f69722c2353996132cde57c7a7a252e380703ac06a5df08e0b5577
MD5 ac71545017f9ba46d48d889f404a451a
BLAKE2b-256 6a130fd1ae7ef0c0c74c0f7086c3251c8f537c1cccc7d87a11637a80bd845b39

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c376a250a1dfb8951b42e141e4912a4b48d04f2e07add8485233d51dbac5a5d6
MD5 a857aad0b87c9b4c48236dd1500ec29f
BLAKE2b-256 a7133cb482027d21b6ee75bc1099c287cdb6e3d06575f5332b8c4438ac267774

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9688a8afa49277b2616315f68331034b458d9f0e6b5a4875f0b5e4c93ddda1bd
MD5 0e38e606220e0a0ce014ffaf6cfb659a
BLAKE2b-256 7c840bcf7580201161dcb1bdcdeba84fcd1d82387f2b388fb1257ea6d70945a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 958e9e4b90a88adade10db3fda76429047d720391e6a19c62ce0d9f1dcba4eec
MD5 70d237f55f812630046858467158dd12
BLAKE2b-256 8c75d9e90aa09d31c683dfa240f9c8c351396411e83751f578a7d071578bb2dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d48efc7362fdcc0c3ee9a8f7150675853fd82f1c6dbc81830217d177f11daae9
MD5 37e90bd08767161ca2a569441b534182
BLAKE2b-256 809fbc485240297f1fe299258f4656ded950f7cf5160efb2f85715439ae1c751

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 894571aaf84d151f4176b4950020bb8511b017b1346f4b5ad563053e4bacdc37
MD5 ff9dcec0651e8fa3e672aa1debb7c07d
BLAKE2b-256 c5f79b30106fa82a36cd631fe122649fb122600cdeb4001a9ed7a622355fbd76

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 014960e423db56f2f709b5718cd616523e7addaae05f9a8d8bed9bc198c4c3ba
MD5 65225486b3552afe79ccae22517e6814
BLAKE2b-256 23e6b5659477bb808629165a4cd617c29a0ae8be012f8eb4b09181d0a40d7db7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8475f0a27df11a1ff7807e007a87e8c540fe87b66b3524b21bc463f5fc7ce0c2
MD5 86b58168d1d5efc8c573cb3a0332d6a9
BLAKE2b-256 38f62a4ca9616c4828fd10e4bba05bf30cb2c1ad2c31a0484007642af8f4fd89

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 72fe8aa2ead48cbf07364aab27dd92074f0be7b437169485e865d1c25ab0d291
MD5 e4d48321a76615c256ee53b27e2a257f
BLAKE2b-256 47cd9861e5f200cefbc15219e0999a5235d0767b70d8a5a99d339ce7a8232818

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f06ae2afc10684a3509167601811f2623852db88c8ff674e589c362f783e57c6
MD5 7d63c6b4fe34fbe85a2f54c0deff6aff
BLAKE2b-256 0caa68625b06c4b8b5f6e2d6cfa240f730e0718987dbe56190a4c8f7a64ab8a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bb6d5eff33319c2061c3e679fc763973591915411d221b9bbe30a2a6e04014c4
MD5 9fe780c378dbff15ace84af6412729c6
BLAKE2b-256 9ae94d8b6521be7599831530bde0f16e131ced13e1bf95228b48779c63d9cbf5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 53fb88fde3aad9d89bdaa3a216e3e43387a52a9799835c826c43bdcfa0c1c2be
MD5 f35f97261e2a9ae2dbfb480d5dd44c21
BLAKE2b-256 8d688980bae023f6621534bf44b7f60c22eaaf957834c0f149dfcb50de340de3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.16-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9838b808f158cad7a9751a2fec318fb88da2b791f62415f4a22fdac71efa7a32
MD5 8c8dfbb6b1e2ab793d8828a09ffeca1e
BLAKE2b-256 489342930f93038a84103e9588a16aba731ff9d6ab1858ec504aa15fef46f4cf

See more details on using hashes here.

Provenance

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