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.15.tar.gz (69.0 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.15-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.15-cp313-cp313-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.15-cp313-cp313-macosx_15_0_x86_64.whl (568.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.15-cp313-cp313-macosx_14_0_arm64.whl (563.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.15-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.15-cp312-cp312-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.15-cp312-cp312-macosx_15_0_x86_64.whl (568.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.15-cp312-cp312-macosx_14_0_arm64.whl (563.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.15-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.15-cp311-cp311-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.15-cp311-cp311-macosx_15_0_x86_64.whl (568.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.15-cp311-cp311-macosx_14_0_arm64.whl (563.3 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.15-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.15-cp310-cp310-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.15-cp310-cp310-macosx_15_0_x86_64.whl (568.2 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.15-cp310-cp310-macosx_14_0_arm64.whl (563.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.15.tar.gz
  • Upload date:
  • Size: 69.0 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.15.tar.gz
Algorithm Hash digest
SHA256 0b44e504c98c493a6c3f2f7261c57514101afca8100b3561413cbd15f7e908dc
MD5 c994a57ddcdd9d99f53e70382a1ef152
BLAKE2b-256 ee8ebd1e287de10bf11c840a999a66d0cf6244196df459712db67cb6f12b58c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 093334cc394322abdbe424d49e2684d8150fb72caac765b4db660322691c2bbb
MD5 b2c69af9c76b2d7269fd3f8ae6faa14d
BLAKE2b-256 f81267e23efcafd6bc52103f75de51180b414ca5ac46f8010972a53e536c6f14

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b185b0e05f4dcad6a3ffd1ea4dba7417e50f772dafc7d3ff264dab72051e4f57
MD5 3f8183ab7676fa88c4b4095df289383d
BLAKE2b-256 920faf5d6599223c9dddc8bfa434bcb3538b24f7f46a4469f8bda9430db03cdd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0b6cf352bf019520aaf25fda179ab1757e07e77cdde9a5e10620623932519b70
MD5 fb2ffb0f7845239908afacf8d028c30b
BLAKE2b-256 9a54cb757eacb1024e80e12edfb93d8d49c2f66d852d5b6302436bc8bb2dbfae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6b953f0c0bfcd6043e6b93d5947d32624db5579ce2f7041fb3111673652f4dda
MD5 963a2ed9ddbf0adbf958936987610bcb
BLAKE2b-256 e1aacf2ed13032fc09c246250ee241c7d7fd6d383541bec3d7fcc5f441314d94

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7f7907109bbac456c5e871ef39c0413ba54e9e3fb0df2715c2e6c4afa07b62c4
MD5 3ba9487f5e97a3108a59fa9a7d4921ab
BLAKE2b-256 cab63525992d4716f3863ee04ea7b63867af2a66a110adfb81af3d51079dcfa9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9443e93b217d6a68f5b0a5f7427604ce0c1464fedb4173e906f381567a31dbeb
MD5 0d4c2c756fc95719bbb2ab0d43b7f671
BLAKE2b-256 37e8b9c3e9ff2fb6161c6946c014c4e935114d6ef606714ed4d22a074c9f5778

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 66e5c1e0eb87d61be8a16476813848840767dd07bf13b8dfb8850ea1d4375a2e
MD5 6ecb5d288662aa719fc9419115634a6c
BLAKE2b-256 15352196ad366932702faf4d2731709ae6610786e2199bda057acb51eb409c70

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a6c5cb578bcb9e958ca8b552e06e4dc69c8508fc2871485334b04729d92d0d31
MD5 e886b37c482092b899ac6e2a5aef7278
BLAKE2b-256 6396eff3644213c5195870b91dd87adc20169ef7081f274456e6f4b8ad709b90

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b4358dd6140dd7a8c7f95658bec01e0ab92d632bc55bf5c330b4d341d493407
MD5 d649d5ba5e1c5c767c433ebb91d918aa
BLAKE2b-256 88fe783cfe3af63c560510012792ac4e392a31de178e671d64d0bcf326592162

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8cf945be7f8ada433397ea704d695f8a7497db1f4e1a6d8caebc18079f84d96f
MD5 2693fe8a4c73fcd5f392cd7b36352511
BLAKE2b-256 e8e2af8e69a0b56a9b80e1b4b36e606a67bd0e0de256fa2a69ac01de5d411482

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c904ebc6ce08d2df33a8a3d51e5cf70fedae3d194fa5751db9bc02311eae3af4
MD5 8554a158266ed0a12a9f958def53b363
BLAKE2b-256 85f2586eb01af4558784740c15c035c536f4a90fdc32a518ec6ed7507be194e2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b3da55fd6fc4e7655e7c313d2b71fce353c05d66f3fe8cd28ff5cdd3f3715f54
MD5 0d1679c37a6dd14949983bd9adba4931
BLAKE2b-256 0d01aca982940ff1f2d93b346876ee91b0fe4ca88eb957c00267907f9255a261

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c026a01716b7c5b61dd1e7d8ea200e44bf70958ce98f9b19393b15f225c565d4
MD5 ca6c33293176e0d1b1b3db394bbaf829
BLAKE2b-256 2e15ea99f83cba45819d8a7035a29ecb5eb1ffd94e1c792c21bbdca0022a88d0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3114fae466f8d6c3dbe30563baac2c4a56bc0e2093bbfb5c595cddb7a1b45dab
MD5 afb5c9efcc9b789858b2e129060d087f
BLAKE2b-256 bb61d6772ee981a979e15b3319caef572cd9cc445f33add35bfd621e338845e5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6f6aae6c2c172fceb5af3f92c3f4bad8c5674ba2b1979087298bc99d593169be
MD5 edd24b77b81ac7ea7ae8583627fb502a
BLAKE2b-256 7f8ca03fca08507d125c6f0189c17fd9ef31b8c5967debe070c8a0b79d4f73cf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.15-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 62cbe9c7a7b12e32dff01d0ac2aff7f3db0f60c16f1df06e2076b2bcbc7dda31
MD5 5e220732aa2a26e02e77202413b52895
BLAKE2b-256 78f5ca2644566a7f4f26bf79c05704bce7e51c55eaf01c38c11f71588a26fdc6

See more details on using hashes here.

Provenance

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