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.58.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.58-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.58-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.58-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.58-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.58-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.58-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.58-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.58-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.58-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.58-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.58.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.58.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.58.tar.gz
Algorithm Hash digest
SHA256 c93cc75885473853383adadf3ce5cced5ab3ad979659649dee9d289630c819c6
MD5 825ce2b71a5c85d7a61914c0bfab705f
BLAKE2b-256 04f4eea8bd573a4f193fa54798c1ae391b6cea4d39483253b03f3f3042f8f913

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 81760ef0ab66415951a1b1d00ffdbac8827abb69a51b20f663f41044a0480713
MD5 4a4f668819d7f6a0adc334a35ebb3cbd
BLAKE2b-256 7a1182ff796192e79e5c66217754cd53b2ba6a28d14bda4520e323f5a5d9c4f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7f09a07415d75284a83633421c8c0020849858ad21c995f2f46ff64ef58071fb
MD5 3de5866654784fba850860fe23aee34d
BLAKE2b-256 3be5c3167607922d0c9351ee2395162673292ac52e2784232a3eec78aafdbd12

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f62fa4cf01330a879013b786ff08a46dace288847c2df4ed02cf7500855d9b67
MD5 e14e7a5d4580e66f31fd2798464fda8c
BLAKE2b-256 9cef725176533de4d2b2355df2609e8d0e2268490fb26c419690ec9461932202

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5b1e62c7025bb3714534fd608974ca455057d6e5686eca4eb747d39c7d33acca
MD5 76f91cdeaee22dc436a748034d1b9cf7
BLAKE2b-256 79aaf14226f5280155a98172327651039a81ccd460cd3088050788e2c0525095

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4473122cb3e7eb0f135bb04df30acc7b4d255f2f85878ddddba6668855940825
MD5 a49626713dd75c803ac5cb31626c1bd1
BLAKE2b-256 003e7517b13aade62e0c648407089516f72a15492449d5904df8edb58d862d40

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a2f88c2e3ba503a196ccc2214269e20934ebb6798522afd9d68a6c4376366cd9
MD5 e3e9b28c5cc067981672d9986ce90fee
BLAKE2b-256 09ca373c2b9527591ae0dba012f93bb3730c3cc98479689ff53b85049f3cea56

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6972aecffc5a6603c3eac8173b77e46d54f79cd22eeee1add3c76c2bbd1f17d8
MD5 066c1acf466fbeb16c4d5386cac25194
BLAKE2b-256 9e0c6c926da245f71e314f59acf27816b683bdcfbf065f29579371f24f6a598e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 19e3c07f89ad197d59ef11a26953364a5ba83998851befc3024d4fb35e32791f
MD5 c6c700d3af2b081d4bfb8fe031100776
BLAKE2b-256 c97b7795537169ad6a976ee30c3bcf42013f25aa311ec3076a56b5800008cd46

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 85e988ac29e2761d2a3f5e9cc49ed9cc5cc20d63eefab65daa28ae9c87bcc530
MD5 1a5143d567487a13966a3ef4e15dae09
BLAKE2b-256 e758f55365c099df35edb24ceb688e35b0cb2c791c62c11248381e919ce4d9eb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4b7f1bc31767e9c8468dac6f25e06a5a4f3e4fc914590c6220eba805476ae8e6
MD5 c4be55050a89f1f176843eeea3c0a988
BLAKE2b-256 aa1c7ce9e74b7872c392b08639336f467c187030485cc77cecb1b038fc77bded

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 bcbf0c89cebc456150717b66a4ea5ffc532bb8a97fa8b5a19d5debf715367de5
MD5 4471d0c9aa706d27446d31a53eeda800
BLAKE2b-256 eb0b844f12883ad2a70c11aefdce49ecf628266d122c13c76ab2b462c507ffa4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e720125ceec9b91c00dd1e13a1621f7a398f122689fab43e1d96366dc1fe6b0a
MD5 0bdcc1c8f42f151eed813c4f61d68d91
BLAKE2b-256 39b75a4b20d27506f8539f99f9c6690e2369a45166ea17bb36a80a09c7ae7fb7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5a86fcc11c17e292e1bfab32e2e890f31ac3ad46f6bcde54dfb4c55b0e8c515d
MD5 58029a0741d21f9087e2dd20571b3598
BLAKE2b-256 eba5f552f9569e4273d1a93f7599d9695bb1235c919a0e3e6740c718f1230309

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 654b063c37121c0126c09d8f010e2f1effa9445b9b9d6c8c89b0c47869a466f2
MD5 3bbb2ba17448f535685f6fc9eb192ef8
BLAKE2b-256 acbcb1a1b664294d580564ac99f3f86454ef1f04273f0687600a8d01c2166564

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a2bca32d97f1038def367641f5bf6aaa1831d29e0ba74b5de820e3db431e4028
MD5 333bc54f8f7096676f14255c69a8aab3
BLAKE2b-256 f8c81e776eeda1c939053b4e2515be50c7f51731c4cd7bd0fce3340eda882be5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.58-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0c62ebe74d75c4a723bbaccde1e4d9009f81bd358aeff6ec0546ddb1ac8ecb55
MD5 48c388a6b077830d262ddd37bb503962
BLAKE2b-256 9f49846371f571e8eb5748e77930b457fd541863857b3072aa36e8a44023ff95

See more details on using hashes here.

Provenance

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