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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.68-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.68-cp313-cp313-macosx_14_0_arm64.whl (654.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.68-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.68-cp312-cp312-macosx_14_0_arm64.whl (654.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.68-cp311-cp311-macosx_15_0_x86_64.whl (670.4 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.68-cp311-cp311-macosx_14_0_arm64.whl (654.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.68-cp310-cp310-macosx_15_0_x86_64.whl (670.4 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.68-cp310-cp310-macosx_14_0_arm64.whl (654.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.68.tar.gz
  • Upload date:
  • Size: 92.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.68.tar.gz
Algorithm Hash digest
SHA256 126557c092856d0ecaaa39f6d85a7d2e69b9ad0d181396a16954e49615faa07e
MD5 6c6cc13ab3c63e714109d53484a4e7b0
BLAKE2b-256 438dbf34903d0983b983862e80a8ef8c6d45b46706935adaeaae05ad7ab4d60b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6db7288e08bc6a8b9ae7da77221cd20670c4bccf4aa240b3164bebf4cfc9cd39
MD5 816635389c4c7b0c18e8d1ca794f562f
BLAKE2b-256 aded90c19806ec465f14916b3ee62d0a5fd3d2bbca4f97addeb6c52661d29a26

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f73f79524fe2d9ac88768053bf456e7cc59b1326191194117830c07ff7bdf1b5
MD5 b260b9f6c138b92f87f0deab8a9c03a2
BLAKE2b-256 6906eb043dcd3344cd53774b348a0cc187f1022f732f39650f840ee45e43a8c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7b485be06bbfbc0648fb8be51d32c8f4a444175dd6154219bdc872817a2a9a7c
MD5 e5ac0079a12d258fe33e3e921185a10d
BLAKE2b-256 316d7ce2443f2f5e58a146c3a54554b6649408bbe80f1e24a866e4eca3f44a3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 da605284cc1e6a633ab6235123966cf693c7d7e5cb77ea4c4abd8b7c436ea59b
MD5 2eee32df7b84f8e669adf36b12230337
BLAKE2b-256 ecd91f89abd28098365580ad279575a92f8c4282d0ad07b4bcba2b98c8b5b999

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 89c616ebf4ae641be80f755f488d39d5b87e42cdfe731ed3b4bd9b7e270d2e28
MD5 2ecfbfecbe6affdcf8c7d69a57942187
BLAKE2b-256 b36482048f943fd75ae5a2a4445dfacb1e412ec8aea3b5dc36c88fa3cd7cbb16

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 50677ebd9145cf119bdf4be752870a662569253c0abaecc29b1ee7ef24bc6403
MD5 605c7c7a31bd7c8349f1cc2c193767df
BLAKE2b-256 156eeeac7a23f3327d4d4fd6f7d43345d459d05bc3b92e0f26f3203cd4496406

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c9d4f587e9ea84b33416afd36ea08a4efa7d1a270492e00d56f218c1c3cf7ac9
MD5 793eed1c30dd5c638c0920e6bf82e95d
BLAKE2b-256 d28d0dc795c39c8d0971eba534d570a18256b614e5505abc5409f0bebb12d4b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9ef9f10aa290d4ad1e05da031f908b5c3360976bb7a2cae296bb1c28f12e1ab2
MD5 2774f3e568eab54b99801082b6f04408
BLAKE2b-256 08e42b3c7330612aa10bcf29c4e46a85a123171aee3e635a5a0b9f8afa516fb9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de20d007c85537d9345f1c96b221481e7411634147524d73651cf6117182d114
MD5 7f8c6e7382aeb79480c20d225c7a4a16
BLAKE2b-256 1b4f7fe1f578dacf15cacd5326a7690a2ecef300a12123148402069e7c70eaf8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2124f58a1a66a9af27abe72d2bb35092aa397c8f041e5321bf151895a68f6332
MD5 9e0f4025fe1c0d7e559dc6c3d176a04a
BLAKE2b-256 004ab3ae1bd62e10efca2f7bfb9480c64248c41758e5f0dd445fe62c8530c9e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d54f1bd5775c1f92cda0032ae5bf04e4e4dc235eaa981ef43cacb422c4755c40
MD5 a31b9c76ca7adc773f081ddd3bbd4186
BLAKE2b-256 bc6c1c36b43c48cd4f2591526ddb1af88c663ccb0662c7f6cfd7a2152f9bbeb1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7d17dcdccd390e9124b60eb1ef824ca92833f1a9c5665fd66c7d6bd83e0484a6
MD5 b52806c8192c26a90e3c20fbdedf01a1
BLAKE2b-256 375b77a2108323b881c24d61fa9383d16c6056b9f8925a114a6fe422ac3c6f0b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a496eb02e6f9a2724bf5c9678f6b068fc615f24f8705298fa14e657c9189a939
MD5 cf3b5bc14f6d23ed076ff80337fd5ac1
BLAKE2b-256 8e00e3873d0d87e443af32dd66fd510ef8d66d23e7529d244f6185bbb8aff56b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6a30998805b7f969d2ca6170173b0da81cd64b89e8619669477f0d19f81f0274
MD5 7a23b814a87dfda0063aca3348e2f2ad
BLAKE2b-256 410190fde2f437bec4e478ff555af39eee195b599eb094f73aefa5ab5000b944

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0a3712714313764407c99dda05e2a36017e818edd01229825366c95d39c7e2a2
MD5 11e6485353065d2fece216598fc716db
BLAKE2b-256 14b9fdc5324677a3d08aa1b799136ed5983e4dbb9455dcbc4b89c93ecddc0895

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.68-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 16eeff72e36339159995be6f52c030f842064f4f20e6b427d4b7588188e6bdfa
MD5 9baa4367b7c0c4f7127f22f8f98f813f
BLAKE2b-256 3598c558e934ab205b9d562bebc656d210272052ec8edc70702742b080de9421

See more details on using hashes here.

Provenance

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