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.53.tar.gz (91.4 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.53-cp313-cp313-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.53-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.53-cp313-cp313-macosx_15_0_x86_64.whl (668.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.53-cp313-cp313-macosx_14_0_arm64.whl (664.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.53-cp312-cp312-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.53-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.53-cp312-cp312-macosx_15_0_x86_64.whl (668.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.53-cp312-cp312-macosx_14_0_arm64.whl (664.7 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.53-cp311-cp311-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.53-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.53-cp311-cp311-macosx_15_0_x86_64.whl (667.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.53-cp311-cp311-macosx_14_0_arm64.whl (664.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.53-cp310-cp310-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.53-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.53-cp310-cp310-macosx_15_0_x86_64.whl (667.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.53-cp310-cp310-macosx_14_0_arm64.whl (664.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.53.tar.gz
  • Upload date:
  • Size: 91.4 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.53.tar.gz
Algorithm Hash digest
SHA256 76ddea6db61d97000db86690840be7febc1d5a4999ccbe5f04189ea6530cf4a7
MD5 6d574903abde4860cd59331f1b730280
BLAKE2b-256 03140d8ab2055da4cd31610a7b9b51a73b04440e8f98ba4b825f4131109a96dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 863f857de12f768fe0107753bea6ac354b8b15029b6174b7f1a60d10a6f59603
MD5 458e7d6d044fdc04ada8d03a6ca27c56
BLAKE2b-256 92dcbf4ab0fce17983273dfb66e2f5654ff11748805900c4d02a1d33f241f7ac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1938268c1fdbe02db72dcf18d77eb4e221359a4f2f6451db2c5b6909b4d95b62
MD5 626cc015fc1ffdda09dd9677cfa9c7fc
BLAKE2b-256 a2b5bb2191ffe7e015fdcb81c7a94dbe1371c6c95bb3d63ebb43b1149bd6137c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8c7fb1419c936ffb2f8572c0b7afc86cbed3da0154f0b37f8c1281b2dda72137
MD5 bf7c1d25619e530f74888aab90124e5b
BLAKE2b-256 1d85397b17442356076df86316ab640d24857a46aadc489a0222a99d8b9a3e12

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8e8cf42b015b86ebcc99f042d220bf5414f271cfca912e7a7c0c0589c8eeccf0
MD5 b9ebf8abc491d9d3bb02afb30315211f
BLAKE2b-256 f8654379a963cd325033ef31106ac8ae05df232c92d0ad496155ae502bb2aa68

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 05b74b75a4b60b1df6104c1149134bee7131fc1b7f0cc620703b5993f565254d
MD5 ec54ff3ba431faca132dbe144e03d5e0
BLAKE2b-256 a3d823c2b3305951cefb51434a172b2483cc4c774c9af7cb0c5fffa16d877516

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f954ed210bb644b7efb0bca1e73ec72a78fe3ebc579d7f1d378ddc83511cf58a
MD5 bc8a78b6a15b2a07b88ab94bac4b29d8
BLAKE2b-256 1f8dca3be4e8ae245b761cf7ee3223361cd150e7a0b62603eeb02c7b7964f0a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3eff6ba0dd06c11e7d8a4e039822e2e72310fecbd8202b4e35dac2e3c14fac9f
MD5 83b3d47242b1cb5b2c868d77c5a2991d
BLAKE2b-256 e4ba48b2c07ab5781024e75b5f1bda8fc29510adf1700a820a835875603bfad5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4d3de975566c18f28350e3af9f2a80ea3cf42d47eea344519bf5dc5c80a3c28c
MD5 f7bbbe75790aa9f66f6b85e865280631
BLAKE2b-256 de6ad0e465eac4d401c4a304cc9eed0a30716ce513ca8c7b9dc51653cb39ed2a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52a12dd6934b14897c512b8c0c33b8cf607cc4ab90f7fec7ed6b624138bbe898
MD5 e5529476b42c78dba1cfdad31c01377a
BLAKE2b-256 5424c788a048173515d5a59e7bdf9b0800ef85da90689a991abf96a9a91b4ba3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bfcc0079a19aac377eef6b5580a770f189afcc0ceec0130e98442d19b76d07da
MD5 9bc8676834b32b4125be0400394b0e98
BLAKE2b-256 d098b81d69093f7bb756696163adb5f69b96351786d43dc702e6ef959aabb37a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9c2f4e2683bc1850869e90adda935893726806ea1ff6e84ae22621f535cddd4e
MD5 4d8637799dfb1faac5d5e2f26184989f
BLAKE2b-256 5eddb469bcb928091cfdf38c49861d5c0ba234e4ac9e5e6399c8bb773eb262a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ee38a03a208577f01f9f5d70fc5b996ba1bcdf39dfa6cfeefe39b4999b3846b9
MD5 b11040f9d8c17bdf491d98363ced8575
BLAKE2b-256 d30e3b316a7041366aa70389881e2f901a0aa6650efba17051f5bcbdd7a0376d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4c9f5fa342513922d73718e73ee9ec142160ecce38d870ac0bfb73daf77df952
MD5 b3b67e1790e451ed4e25082e0bf331ef
BLAKE2b-256 6b363adb9529b48428a065b15bae006edfdd1a3dd42ba9460a0442780843f010

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2239d14bb4afd2e07f4f3d5046249604372850232673ea53e52f191d21ba3b0a
MD5 95b128367089b6a99db9259e28258386
BLAKE2b-256 14b7ab205283d41d96bf330342d69c9bc6692bd50fb15412e7360e6f73ba2756

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 553ff8350d736003eac5211ae3514b238dc3d613a6eb8b0a3259c3c35b77cc54
MD5 5eaf6d2594dc41429239092fe19b56b2
BLAKE2b-256 0112ae0b7c4d1548d5d5c0b4cd1235e479a33588a7ef913ac67430e9303e4af7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.53-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9e4398fa26ff3e5bad1cbc09617251e01e8d146fecb17b3be2243ca267ed7344
MD5 b0ec61033583ab3505e71b72fc7c5adc
BLAKE2b-256 8807b4f99178f4e56ac3c742dd3354ddded88a5b4e68431d4a6a4834131fc466

See more details on using hashes here.

Provenance

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