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.75.tar.gz (92.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.75-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.75-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.75-cp313-cp313-macosx_15_0_x86_64.whl (665.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.75-cp313-cp313-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.75-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.75-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.75-cp312-cp312-macosx_15_0_x86_64.whl (665.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.75-cp312-cp312-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.75-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.75-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.75-cp311-cp311-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.75-cp311-cp311-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.75-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.75-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.75-cp310-cp310-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.75-cp310-cp310-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.75.tar.gz
  • Upload date:
  • Size: 92.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.75.tar.gz
Algorithm Hash digest
SHA256 75a0659864276bc32241af6d55e7521654598a5e950265ace095bab239bd6c76
MD5 f48b90941b75b9a56e31342d8eaf0ae3
BLAKE2b-256 e81020388a0121c0c74578ed84dc038234e476c5e02e79bd38e1b8634516cdde

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b55c19c4533ee17261d00d9322fdd2b998dfa4af135f885e25db576d7642435
MD5 4470a2b4293bab5115c2f9abb15cdd97
BLAKE2b-256 7cfb818cd2e8c34e588651e3a62bac4f60618926b860a03081a9b15f600896f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f78e6f013f4d738e3095690c8472837af8f79c49ecb140302ba591df47d89fa9
MD5 ee886b3ae9c89700862190f49641d2b8
BLAKE2b-256 044d9a2a78a2560866836078813638db3f5f9c5eeaa2e955803eff0b334bc31f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 cf0a41135034813b6b06865ccdd9a421bc3c560abfeb57616cd9f8676ac77a72
MD5 08795be01011c9aa12b5190e1822326d
BLAKE2b-256 df3a0acc7ebad37dd6e501396f74b5e75d78d3a3ea4ba04a702b6dad11622505

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f204115d79eb38f2965aefdeb4b1a4b0f6b49f08443aabe79f3b3ec42512707a
MD5 784d4ec70415175d7e0c5f958bb744f9
BLAKE2b-256 f52788e28a44da703c326a4f1ad71bf09adae666e338e3234bec01b7130f90e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 92f51040c69b3de0f39007499a8fca06b0287ae7908eb000441a03699558fec8
MD5 8fa6a56dc15c159d9f57fe26ae43d76f
BLAKE2b-256 f3b6db4a088674682007668e9c1fd424f1eddb755bd38813c33bf886b373fba1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 50eb2e29748447191576c6a00d90324c62103c545900ea6fb5335b3778422863
MD5 2f9d901db9b0ef15c27f0ac17b770811
BLAKE2b-256 eb93682b8bb5738e9ffc2e635cd53f8aace38673bf9c899a1672ba793d63a5fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 55b59b7b5eee15b14f01d547e9877ba28fe8d8700d9ee6fc9f791c71b57c3864
MD5 24379c226b5cd0bd2f5ebccd8e9a7d87
BLAKE2b-256 361b288e18e582085dc3474f75342e129b5cc1e72308bf11a3706cf2fe3baa38

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 042921862b646bce4a53918c2ad970bfa367cc345e9b9bc4aac06865c7307625
MD5 542d43a61f7e1e92a11560642ba73fc9
BLAKE2b-256 df75a0748ac7d41c12b169c3d6ffee3b09ab521fae84f35c08e99ff0354cf712

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6717770b131a3cfb7950ec5789f1e6b28ba7c71deabf3b329ef5382bc091c697
MD5 6eb1ac442b95386c462a603907f760ab
BLAKE2b-256 30da372986cef9e0489f4ff182f304b172172d0f10382773843eec18ebf6a29a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 86a88ac2b86d8222ccee2faec0eae00c591af998e50b2fad1b198cd0950a4512
MD5 7b1d232b86ae9429b5e3cdd178682bbb
BLAKE2b-256 6d3dd2b776cd47867dbab84ba3d2a8fae7847ca1ca5ab6700a8f4b09924e6896

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 20a7669603c2e8f255a9cc879ee2e50039f1a2579386b33d7898ab2fddc17ce2
MD5 35fd126859a4e865d73d22377ae9a59d
BLAKE2b-256 f9a2edfa626f11b76d505fbe028abf4641ac41da386c74847d63720b1b1f5ec5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3d0428191b4f5fd06a86bc067fbf38bfc66fb42057f728d9a52f12c61f656690
MD5 a7dafd8417799ada48e9119f6b6fd76c
BLAKE2b-256 2851b740a8de25744da30e731fdada421b2ce4c23608567ba64128156157b7de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 928a5403054e3c9dffd32185f81874297351551e87b8ff7bd55aa50d338d82d8
MD5 63516923b83aa8a940dccf823a7d7364
BLAKE2b-256 1ad11ffd095dd3d9134eaca7c2f7fadc8bed765b7a50c49eb7f564c4da4d6c3e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7bea97ff55509b1ae43001adcb474e75ea428d0aae184d1cb83a1bc9d2aaa376
MD5 9c73a2fe4f0c355cd4afc15cdb2a4cd3
BLAKE2b-256 65f3ae65919874e752c58f009fdaeef0414639206ecdaca07d458e6ff4d28189

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 387199ee92714a844c7faf5c599c9041cc00d5056ebf96205fa2072c562552db
MD5 a0fdff18978bdac450e88df48a2e87ee
BLAKE2b-256 83be038a73f119a18e1607282e78bf05ce43dbe6dec782f29f37944a1757630e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.75-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1dfda193bc89202eeebac188cc23f593cd6957712f2c4c778140471865aa6e8
MD5 07539cf03ea3ae41d7e64d2621c16890
BLAKE2b-256 ab2ba913e6df2d224d80996f25a36fe1df6b4898514b72230794740b2a64464c

See more details on using hashes here.

Provenance

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