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.39.tar.gz (90.1 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.39-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.39-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.39-cp313-cp313-macosx_15_0_x86_64.whl (662.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.39-cp313-cp313-macosx_14_0_arm64.whl (660.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.39-cp312-cp312-macosx_15_0_x86_64.whl (662.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.39-cp312-cp312-macosx_14_0_arm64.whl (660.0 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.39-cp311-cp311-macosx_15_0_x86_64.whl (662.4 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.39-cp311-cp311-macosx_14_0_arm64.whl (660.1 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.39-cp310-cp310-macosx_15_0_x86_64.whl (662.4 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.39-cp310-cp310-macosx_14_0_arm64.whl (660.1 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.39.tar.gz
  • Upload date:
  • Size: 90.1 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.39.tar.gz
Algorithm Hash digest
SHA256 83717e8ccac2f5b5be39f29d1ef9e2c5d0322b504721726a2dc9f253cb41b847
MD5 55e98e8a4987441e5766b01978ab94eb
BLAKE2b-256 562c7fae662fb087463e892f0722c9fc923c711a4507f83f0a85ea3f6b752b2f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1821d5f0acabf2272dc8a2ec2bbdf769ccbc08678bdab0ea157e574296a09079
MD5 f738d5b9cce3f410326820e5087bb92d
BLAKE2b-256 be486376f751ac9970dddcde6f3b8402b5fc89457e44560d11765914ee292d05

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0c07fc96f53680264fd0db536c547fdc357414f0e75024e7eb0762c5ae86169f
MD5 5c3c5d7a2c552d61e0d8bbf1790426be
BLAKE2b-256 38eb9e165a29cce1c58aae116f031835fe7fecd7532dd04ffa71fd156d83ec39

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9cc6107a44a0a0a28f71929210eefa8f28aceed87751434978d6c4c57fc1b61e
MD5 822d49a2ef6cf95c55add777cdaf9278
BLAKE2b-256 036fcb23ee3dc31a0700076769db285d178e1d6036d9575768a21947ac11957c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c49f70ad6f6794111f503dfff671a633ec8993ee9498bdaa09470379afab7d42
MD5 0086bd68fc43ab6c2d95904862f18939
BLAKE2b-256 53dd4278010db39cdfae482015f69cbd96afe2983d3d535aa01357dc96b4827e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d30c19d0bb09cf7db6f7d3fccd193a83fc16c269c56a41317fcbc872d7f6e388
MD5 9a468f1ecced982095b052e208e758e9
BLAKE2b-256 849c3270f1e0254488a81d6b6f59f1b4093f3a69e4d0660fe60a09c07ca6d425

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9645e6cd85c016697919e1881a4abd5fa1a7aac5ca76aee5a160edf1ecba4d8b
MD5 a387c03c48ca7199d1ded856e490ce52
BLAKE2b-256 834f96c0eb9e3debdb0464c71ea712391fe56f740a5680e87d5ec93ac0a3c390

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 06b0ef7054eba6c969315c9f5c605ad7f1c709fb072e060d09d0609adcc1eaa7
MD5 b80759f4766d07ba8169b6bce84f8fe6
BLAKE2b-256 7092753dd1e0f618d0279badb9f345144d724e6212974df22b4889da1fa3aaed

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 993e007b28b7e7084972092947ea3b3cd4d72708d125e85f41d3297af9639d85
MD5 731845a1d79a3eb5f1bf0d14751402b9
BLAKE2b-256 14b2d4b7782d3fc808f2b306890fe2168700e4cdb614d04c6a8750833a01f86d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3b9d4cbfa1f0ee2093ba5c391a454e45bf68f3024e4f5def3c102a7c60e53375
MD5 b7dd02fc07c1d634047e00ed83123ebf
BLAKE2b-256 dba0411acc61107d7c9e62aa7c90068b7d94f7085812ba1e15f70c85edab277a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3029a85c9ff764cf454e6a47633c571b48d14e9c8f212a6b2c4cf9772f424825
MD5 0cb14cf09eb6d2766b01a4bf62c69237
BLAKE2b-256 eacca2ed6fe21b320db94adfc55bcd65827df2cdc4e02ffdb97a9c014ece23dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 928194757729303b1e91360aa0d33fdcfd5fc0b34a15cc0e8d458fd5d39831e2
MD5 9c1fbc7c230d815fa0ccdbc844c1e97f
BLAKE2b-256 d1b5b51b348a3ed6eb49702f5c6c66bb9fd5fddef0500fe371adee42bd4ab9d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1605a32d6ad2f7c6a642a49d5cfb40acdda8bc34c037441eda28257db5032415
MD5 2a99d38aefe874236f209bffac4a140a
BLAKE2b-256 ffa4ca5d14b2da5cd46f2631755ed9fab88294622f3990c20fe61776f661bcac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f3cef070114a58e8e8c07b1fe498b8f5c6a01407ba525254924735ec87cc2cc6
MD5 98866be1a93ef5e97e307384a1fc7cb3
BLAKE2b-256 a4ce57d96b6577a4c0f6302bbe13e66bc4594d394fd1dc5e5a3e7a0868dfbca3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fca82549bee03b3b717be01de99c38006a2cd9b5399d7bd4b0ca5ea2780e6c5a
MD5 e395c66b12187ed3f99366441b8c8e30
BLAKE2b-256 0a60025b9c580bb7fe001bd73476699f764af03a67a66e440184c1f687a655f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 431a2e75a58ae1b090f7b69c956cc6e2938aa6d79385b4cb155fecab67b86545
MD5 c884acf6b905833eb65a369cf8456041
BLAKE2b-256 98410dc8192bb409ce71b8cb262c1df253b29321fc1ecd4133c3530c23446153

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.39-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 052a3d92eaa74c1ce58f74c9fc485e667acf38bb15b85595be0f2dc0be8a3489
MD5 fe4cf65f4b704f41201176e59d6da0d8
BLAKE2b-256 b2049b535a65c160e2512c0277fd0271005649a139d2116649954ca1074a32a6

See more details on using hashes here.

Provenance

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