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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.57-cp313-cp313-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.57-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.57-cp312-cp312-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.57-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.57-cp311-cp311-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.57-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.57-cp310-cp310-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.57-cp310-cp310-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.57.tar.gz
  • Upload date:
  • Size: 92.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.57.tar.gz
Algorithm Hash digest
SHA256 943fa572a31090fb18d281e640d0b7b5f4130c2584e4e30f187eddc5e3b8e76b
MD5 d101fe67be7ffda4e1dbf5e1669a247e
BLAKE2b-256 27aa533616a183a2dc654085b24b972c05db70da0fb721f68bb83347a4ef3f15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b3d4f7e34aa54369b1b38ceca8608733c440888a552105bd4df7be368641d854
MD5 65a7d10192190d17356c76be0ae0208a
BLAKE2b-256 a7d831d3a94d4f3982d6f90cfa44b755ce414fdfd2969990c61401ae5047372c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 77a0c341ec376f3281ccb2e04defe73432e67e9f48f1f7aeaa0c1fa886660e29
MD5 4554411d6e51765251de6c887f5a024b
BLAKE2b-256 21539923dc003234ed8de61e9b5a46024a1b21d416ef239ba35382dab72a00d7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3ab4e4e7ace621d202fc998dcb969c528d3e83ebbd0c323be5f44aa8bfa00bba
MD5 2f1e317b0bf0bb67785a27b9bf2ad4fc
BLAKE2b-256 8404d74b5bd51e7d008b76ad5fe0ad611effcf4891fb1d0844f3ba25da42d49d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4e920c66d557d19d47908ad68c4355b581dbebe8b3bb478578b6a943a34bfdc4
MD5 c36472a8383ecaf0322e752574fe4a64
BLAKE2b-256 094064fef3c03db1f1752465cc78092432768c628c145045efa14ba1a7c1574f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a037969d68c80b5ef35c1048ddc14f9628d9a1138d1d2d2d3addda223f9fd73
MD5 f0ee3e655c6e6bfd4b6c2503ccb32c82
BLAKE2b-256 1479febced16713ad7f93869030e0e4d84c8103f6f27221df8fa12b9cbd60b7b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 52a0c884b940f2914c26258b9588db3d026d6ac5410436d345b72784b9d53996
MD5 869182144a38256c82b24f80d135a5f3
BLAKE2b-256 5cbe45d010db91b0a4235906fafa24ca361e01ad2ea2b7d7a05a81893d6c26c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3547ba3dad6b2a01cc603c09e37139fcd89bc7d6e7ee68f253dfe199e865d5bd
MD5 28ae6d0ce37d6e6bfa42665777e0410b
BLAKE2b-256 31da6d7a3853a775233c1ecc54c26393a3a33e6061ae3870608337a7929e4562

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 36c2abfdad0099015db753ea4efc0db281cd05fdc8166dd97cb942f12719da2d
MD5 adc1b3b26b95031fd20c0fda260f4178
BLAKE2b-256 77d473c42657dd5d4c0c27f2e2b080d78b9dd4a1a97dd6689021ba3e527cd1af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2bdea0595390908cfd673129590ded8e187e342e2f25e9c911713a29db5bae04
MD5 aa3c6b38fb5666c42640a91c75e8bf46
BLAKE2b-256 6fc785028a6dd8afc03129cf9848bf4bac784386ffb6b0a0b02adccafe090e40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 22cd439ebc70488298ba9548dd9f04d31c7689c21a13cce6b1af827c78211617
MD5 4c60911d0ecc2395e1eefc522e078ff6
BLAKE2b-256 af4a73a3c744ca6d819101fee672b04b12e35dea14b337ccbe16ec9830143fd0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a43271e8edd107624ec1ff68af01765cd325c59687db65f21c1e8140ec666f36
MD5 a0fb60fcb8826ea6035ebb2971b8ebed
BLAKE2b-256 f02322de4e508a354423db55a91b6004ac88646553ffb8700b64f3ccf0748cc4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2f1cb83b7c369e5f8f3949b7d2ca1667405536ffa799cc4d8477a1f50bdee76d
MD5 1f51f49c69f691a79c9f5b22b94f70f2
BLAKE2b-256 9f00cb863028454aebf28d9cbfddd7dca19c6c497b4ce414b453d08934b5f6a9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1493db7c223b5e6b3e9e278654b0cd411d51a6b284fe852a7ad5738ac38cb881
MD5 54796b31a0ae1a3583ded754a7e5817a
BLAKE2b-256 31e24af0f58e026bf0ac7da2510db90d64e84aabeb42a7dc9656ff71be89e59b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89aa5197b10a5103f3569b1881ffa4a3124e789e161eda260351320d423783e8
MD5 5dff77923e8810bebbaf63cc3b9fbdcd
BLAKE2b-256 85123b3bdf3e10d55f7f593050a39fbc8d28126df8b0b9731ca93ba7bfbe739f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3052f95c440d08b364507ec1fac0b366deaf3e0b571c82073398ab45d311f74b
MD5 90c8736cf50aae47c9a1c6417fee6466
BLAKE2b-256 81baaaf808cda554f01c51ee26d44949243c6eb90a636a256d34175279b129be

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.57-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0b67d36041deab5463b69356f18551d15c2222cb9edaab85f0d8e1f250dbadd4
MD5 42258145fbedfd998d2baabc9d7b50c0
BLAKE2b-256 bacf62358d70c77b75999e782d0fb0d63264cfe4e308897cb91c90c5fdf7229f

See more details on using hashes here.

Provenance

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