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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.44-cp313-cp313-macosx_15_0_x86_64.whl (664.8 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.44-cp313-cp313-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.44-cp312-cp312-macosx_15_0_x86_64.whl (664.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.44-cp312-cp312-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.44-cp311-cp311-macosx_15_0_x86_64.whl (664.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.44-cp311-cp311-macosx_14_0_arm64.whl (662.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.44-cp310-cp310-macosx_15_0_x86_64.whl (664.2 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.44-cp310-cp310-macosx_14_0_arm64.whl (662.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.44.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.44.tar.gz
Algorithm Hash digest
SHA256 ad1166dd15d891cc713fb166dd4521272d9807062850c4931ce6e196ee132a79
MD5 65f698dfe1a1426fb7467c6d203ba0fd
BLAKE2b-256 57d17cb621516483ea0158e02aaef57a48e83ceaff67345fc88af6c781db08f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eac4f5f24635d5debfc0c5a46c8c6d6dce33443b71a8a4072e62e566d6f22956
MD5 7e5ee1ae228f515d61f30424a6c6341b
BLAKE2b-256 754b726ceace7aa502add7a8a7557e176f559a625d4e5adeb15acd5e9078a2d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a527ef20e3406d13864c89c77f1c042e3bc89e6bb92b96a3268e4c9f0825f849
MD5 dbb28c949a414c9e55b2b6a2c088c703
BLAKE2b-256 b48f3d9107d8c43a4a5a46c5b4bfc068411152ded3de2e178d695b41f14ef901

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 96215cac6db8c5dd4716b7025c42ed1ba27b11943ad27d1a6bbfba376ed053e3
MD5 02637d9c8ca92f5123ece34fc4d79e75
BLAKE2b-256 9feda0992878c4bac5ae8a708aa8cc7d769d408a107f2cc7df079567283b4e3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4ce70c9187f5ab951790be2c5b172e998d8c257f902ab8876c7d71f21853df8a
MD5 793658ec47fbeff7d9ecba858d02b691
BLAKE2b-256 578874cf546caa27498dcc07719e2a7d831a66b05196786a5e537b0aa21c4f9e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b6ff9dcaef7a9896a1f267fd4c91b4537f64571a97e1ddb4511bf034ae87f445
MD5 e3903a4fdc579c66b5077112e6f38f3b
BLAKE2b-256 32962a35c9636da7369288a9839ad6f2f6364b1c63860562fb1d87a3455d8a01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6ade9cde0ed66ff8e5e11ff2d9f9a321d5e6cc4bab1eb103c95366a65d0d2fc1
MD5 d71882f7494f8dbb96cccaeb17686370
BLAKE2b-256 4bef01566f174df074a82fc2271e598fb32aec698fde84b9561808ae94c2c8e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 489d06d3a34750154ec1ea3b1214cc7fd86322d807136b66a0e276ea1bf7e1e1
MD5 2751c135ca9ec0836abd016fceefb13b
BLAKE2b-256 bbbe98a847a501e1b5fe48c0053c55f885175af5065e63db9261aa9a87e8469d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4aef89e32db08442b2743a83010c6a41238ed19173a11d385834d883f7c16f0e
MD5 9800e62088765a5932e8c8e557a12a45
BLAKE2b-256 e253fd1ae805156b3d86a55ff21701d03736708663c795826377b616f9222d19

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8b553f5dedf6630222e02a06e99efaac62127e1645b7a5160580395d493d1495
MD5 b386c307ffa26888de102fdb094b00ac
BLAKE2b-256 795da7a594feb5d90703b0b249667abe1b147d8e5fe9e67c7a630e74982ba6f7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 00a84aec45766b734b5f3700e438be03f2ce3271debb50973b0470bba526573f
MD5 13f8801459b2df4ec69f50137c3507f0
BLAKE2b-256 cde067f8fe6bc2b030b26779802010672d8b3079f6b0cca1b5722414424e4456

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 45418d2c7853c03e5e90a81433b2869870d3c2932b0f7e32a0a8e8507c459ff0
MD5 79ffa642c3491a8be980798724b3aaf6
BLAKE2b-256 d9e0e8343fdc721c1ea8e0a768de63bb333568518bb61806bf1f1ad0acd86911

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4298cd3f8c773cbbd879673c978c2b6317a3f3bf7b7841a7d3ae536f93545f0d
MD5 c2b0f63434191a382401bf085317878f
BLAKE2b-256 78996caefea901ad8d9209cbcee3800f5610443fe1b25d12ae74f64d1ffa9ce2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 039235a3a87023b928edfb068680f55f40de2d13bdef092056ff1af6f6fc047a
MD5 62989b6b8cdc9cb803c1f01f26f23373
BLAKE2b-256 2b15e5fbf6d3f6985d2bbb4c1059ad17cadf49bd0ebfb0679920558131b85181

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 976ed1a0294214d75cd30f57d2181b857826304375adeb443758b28c9df6243d
MD5 9bfa8aed07c605420ec8a432e49dad85
BLAKE2b-256 5eee8d0a20c4a38ae39399086a660a0736afd662c5bf0c67b9b9e5bdf4e9024b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0e30fbd44dcca3581562813631e8f4a0d02958d157a2a727796cd0e07f548de2
MD5 0fb8fd16609c067a556d20015b5613c6
BLAKE2b-256 068fabd23cb19abfdc737515d1a579306a9d81cb002eb528af9451a5fc4d8009

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.44-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d83b86838eba58e742eab9d13018ad68b2adeac012abf0136848ee303f87c513
MD5 1b1ebdfd0bf1f9e18ce625114f374c88
BLAKE2b-256 72b085e3827b4ee9be0e7734637a5c51cb46f038eddb3bbff0fa346abda3ed14

See more details on using hashes here.

Provenance

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