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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.34-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.34-cp313-cp313-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.34-cp312-cp312-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.34-cp312-cp312-macosx_14_0_arm64.whl (646.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.34-cp311-cp311-macosx_15_0_x86_64.whl (651.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

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

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.34-cp310-cp310-macosx_15_0_x86_64.whl (651.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.34-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.34.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.34.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.34.tar.gz
Algorithm Hash digest
SHA256 245ff247af61871a0918a37589c40b481bc814d4ca837b263baf992fb1bd0c2e
MD5 0847ed91f2262caaad32e7bc77e2c95d
BLAKE2b-256 6ec5260320b7b5653cd9d341fe6ac4a63cc730cc06cf95c158f5d1f3c243f4a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cd665d669bee39e24488c49428921ec9bd3469e0c59480aa03cfc35273424e7
MD5 84f18f5cf4e8e7a7ea70f16eb7068eab
BLAKE2b-256 ecb7599da3650c83da73f6644a29e05b08073d1406f80c23706e283525ae9279

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d48d2b0bb0f23fe667e968272a0a648fec680ff1b2388dcb8927f17499d20c15
MD5 c0a601847fd9c10e6385573927b47553
BLAKE2b-256 e3126533734e858a521ec79a5e410db8da1b1e9c3d0227d9e90b2ce50db67bce

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c6c7e452d803c550722e7ee268600fcc4842d36e3f1a28d86aa3f337c1f68f79
MD5 d28e8de5de82ea87d10e1f5ccba3f074
BLAKE2b-256 d3db7b64672df2b49a9d799f460251d9d01cb6040ba8c99351e8d520c71ecb3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d74a38529e70f8f88146c8c8aa12b518ddd7f4e85174ed9cd417c58a8505cdb5
MD5 a799efedd8fe3d80a7ab2650dcfb9636
BLAKE2b-256 7434ab765cf4fc7ac0a609d7646733dd96787e88b2cf68cd1aeb16a7290736c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41a1922049b9a57d37f33027c48fccc167e9b8c12c5425af55544fdf4ab75a30
MD5 1227dba33d0e438929ee7a70a28c0366
BLAKE2b-256 8a2393ba23fac7f48f068f8b7e80834753ab1fb4615fe89954a9ddd7280b39fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e5168f4e65481207f990f5289a0be1c20d1892b3b16807f68c897864f37c4f7f
MD5 03cb326c2aea0cb0bb38a8f719736b02
BLAKE2b-256 507ade2a468aa8343465ed2c7fb2f32dd97c0ce820cf24dd0732e592782d69cd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 11834d039be10c589453733b1d38baf26a61a1c5a4d5b2f5183dcbb14d5ba7f1
MD5 9e9991aae2824420737260280ed20833
BLAKE2b-256 c2935115a94326d525651a6d689f48e03dcae40c7677da41b947b5742f6ac0d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d51d548e983419ef5f03ef102bd1f582ad7596120f9af20be195b0f8c385352f
MD5 c7241b49cc03639f72376fe87d939d88
BLAKE2b-256 30356d5a0ec3ff77ad4dcc9f98ac85e770c760503b7da38b6c4efe5b2e8556d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b27d06cd88bcdf4ad5f28cc59b84cad78a5c366fd2fc1b1463b0c595afe7c2e
MD5 21ee401708908f815f7fda6249fd74cf
BLAKE2b-256 bf1ce6c226298362d5ea11a766888b11261f7b18a4812722a9bc5a94bec6dbfd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e8aff89f200eadcfb47f58cf71fc4aeb2991aa0734524112924d2bae2e49628b
MD5 eb8148af5abf84954b693486663d2b53
BLAKE2b-256 ab6ceb446fc1debec6fa3b718c461a2de457bfcf78746b986739b285d5d13d6e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 93bca1e8bf3c41590d02056bb2849972344c3f81cb4399be1f0bfafe93c16ea1
MD5 67abb7b2e0d3c087cfe4b3cd1a1bf205
BLAKE2b-256 4880220634148559f1f9841f2006bf056e1701c8c85d86c4268c7af4ff39219b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 010af5771672f195ad678fc282c0dcd9c3cee12706140219e009716435270a56
MD5 0ca921f0a812ab221ef72c87fa13c053
BLAKE2b-256 73d9fe51b28649bb22b6418d1749adf99c478d9e3cfbb7df7ee186b1645d2bb0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9230f4b70bd2a385506741fe3ebab970be313787726be84cc3842af272fc5054
MD5 dcc0b52466d10d024f208c12c3b5ceae
BLAKE2b-256 008406526e6c77cb26f02994a845655e5cefe9ad4ee325f3837d7d1650316d57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 43261a8cd340bd0504992c5ca1c838b7baac47bced2c0ed8db2453db5313737e
MD5 0ead24d7ed48a92b56aed422ce57bc1f
BLAKE2b-256 2cab10b72c706d42a5a6e1629e21a1e255b6f7e1df2716f2566c96d6ab05af93

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5abbbcbe91a547f2762d94d7ee1ed62b96792b1488fcf1c3277f42fefbc0f8cf
MD5 1c99e65772ce75cd48067843e6ff88dc
BLAKE2b-256 8db45c398fcbf14a2bda549540af4d1a5938dad6bd6e5f8e7f3be9d9ea020e85

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.34-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d9f8f74496b27b96e45fea52f339e51b054bbc763bb97cb35cd875a0fd704466
MD5 46b14bdc14c80383938c82190216ae82
BLAKE2b-256 89642046a8f44fa5727db729691506fe7dd155ee14f7c8caf332aa326da1f88b

See more details on using hashes here.

Provenance

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