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.20.tar.gz (70.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.20-cp313-cp313-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.20-cp313-cp313-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.20-cp313-cp313-macosx_15_0_x86_64.whl (575.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.20-cp313-cp313-macosx_14_0_arm64.whl (567.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.20-cp312-cp312-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.20-cp312-cp312-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.20-cp312-cp312-macosx_15_0_x86_64.whl (575.1 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.20-cp312-cp312-macosx_14_0_arm64.whl (567.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.20-cp311-cp311-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.20-cp311-cp311-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.20-cp311-cp311-macosx_15_0_x86_64.whl (575.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.20-cp311-cp311-macosx_14_0_arm64.whl (568.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.20-cp310-cp310-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.20-cp310-cp310-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.20-cp310-cp310-macosx_15_0_x86_64.whl (575.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.20-cp310-cp310-macosx_14_0_arm64.whl (568.0 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.20.tar.gz
  • Upload date:
  • Size: 70.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.20.tar.gz
Algorithm Hash digest
SHA256 e0e5a0d74bf455ec7dd649a671811a087d51d2b8f5afaa6c00a85c441b330ad4
MD5 022f23edb06afef96297a76d5e23cb3f
BLAKE2b-256 185ff0b41ac96208544be67fd1cc170cf846a17fdad4be26e2c9a0aeacf040b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a50280a85262bd9256acbfd9e891144480826c283665798291f90a846966250
MD5 5486f2c8285cdd2b165c9282db94db6c
BLAKE2b-256 8041e294db3ad0985fe094ec29d34bbb6fe2832ffd4897af2221e3031bbd37a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6c898fdbfdf99d89070296f0ddba563449b0e7e7dc9eaf2d7d88d419594557b7
MD5 33429b5688e84b57ef9c8cce0f7e57dc
BLAKE2b-256 97d3ce6873a949e29613924bb005abb3b53b9160c3562535d7986585401ab6cd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1ff336e194c38aaffd554c7e75253d8dcb6619aac7ea6d5e8cdc6ba608427d46
MD5 9b356da239eee476b5a73fb62d1555f4
BLAKE2b-256 3789068cc8c6dc4ce864055ee373ad6b03ce1b821d2863cf3a3c675c0ec7b75f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 198d8a990047aa5c674997b5480cddd82cd60abf35bb304f162144749a291eac
MD5 ac3943f1ef84908caf0b1b6df29bf6c9
BLAKE2b-256 f81401a6c75d975e3fc93b7e51f51eadd4894cf6ea1e9d251c050d353d30a065

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f9bc5856dccbca492c323dcaea2f8cc64cf1740568b02fceae2f57cd710b9257
MD5 d54e3d53889bbb5ffd49860f0ca8c419
BLAKE2b-256 4e3fb14d233d8144a20c5a2494e140b85736d396d59cfd1345dca395ae61b26d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f0471aafc57579c4836ba2548b364fdc9d2046370ccd145888193fc5ebc14c09
MD5 b61d2fd1ab076ed42780aeafd599b73a
BLAKE2b-256 d4a3f9567247ff4cb26004c22d520b9af85cf78d585dd387ee771a040a55d967

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1e38909ce02020c2ca3c912e9e46acd929c337550d8ff7a9c319f91228d1898c
MD5 d9619b06baab3afb723499a6e522f436
BLAKE2b-256 afeeca5538a0c6cb184c90233a4cd332bb9c60850eea1766b363906addd453a9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5cd9a969fffd5e5b551905d6c4418e7468dc5e99918411f5e28947d66f0d3299
MD5 251464aa4085b1131aa0e2982db4d49e
BLAKE2b-256 cc0d742004d937561b61ff1393601ca9fa02224c74a09252152c9615375b7aa3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a490ad1ea2b1d99922047f4a2c9f93783f0a439b4526f637dc2f3e1840b42167
MD5 2cba5ece4fc31bab28d86688d533d19a
BLAKE2b-256 2f9c014505068054200493c17b8707978532893c84b7973d4827d11bd016740a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 53ae423491e227702d4e54aa969894a17bd358a3a341d07c678ad091f2c2d2ac
MD5 e04459cd5bb6c6699a7ac6dbf71a603e
BLAKE2b-256 041854be57477fd264e8c4627bbdc38763164c9718b3be81d1d1f22f01c07a15

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ecf79dc8b0fe7c528aae648d9ee429e321b7dc766adcb64b69cdaed48af51932
MD5 f41501163b70aebcdfeda27959479d70
BLAKE2b-256 ab581b28360efbb57a5494939bb98bd343ac0ffb6ca7b37757eb2b0c5743afd1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 95fc47c3d1834c85739cfe439b0711a2fdcb219107cfb5a63ac74c87ee24ffaf
MD5 4699cebfa8ce091cb85625e45cfaa29d
BLAKE2b-256 d510415c646c07c10d9fd42327af7e9a95b4fd857e7e6ea4b7e944434bd3483d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9df8dfe6e1b6a31fd272f4bdff2e53e6086f8eae69c104263e0d18dd10c4f345
MD5 39f3ce40d605c24400267f38503a474f
BLAKE2b-256 8e0c318fb18a07ab362a16c1ae13bec6d2ba43f9d850b6e5561fedd4d715e162

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7ae67323c9cf05865eadf99cac2fdb32f480916483bbbab002e434188dc839fd
MD5 985e9ab653f9c01f36659836920fe739
BLAKE2b-256 f30dc9d2a0c5fd05459495fe30cf0c59d13b0deafc8da60d54b0d674b67ef5ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d947fb1562e3919b9369ac9bb3cb757056c3305f5f683c3a9d3a89007a89f992
MD5 cd2bff25358432f87b92943e28d7b1df
BLAKE2b-256 54b1b1026e78563ac3240d5a787f6348e4ae85f3174edf82aa9c7e78ac402c3f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.20-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 eb2628dd38102287deee086708c1db8d45e5bdbb001bddb777316a803d7c804d
MD5 bcbe94d7e37a282c55b5ae90c0c484be
BLAKE2b-256 5fbd04081d241552daf772fc88110386b85f60c07313dc42aa6533865ba4e7b9

See more details on using hashes here.

Provenance

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