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.40.tar.gz (90.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.40-cp313-cp313-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.40-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.40-cp313-cp313-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.40-cp313-cp313-macosx_14_0_arm64.whl (660.1 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.40-cp312-cp312-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.40-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.40-cp312-cp312-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.40-cp312-cp312-macosx_14_0_arm64.whl (660.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.40-cp311-cp311-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.40-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.40-cp311-cp311-macosx_15_0_x86_64.whl (662.6 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.40-cp311-cp311-macosx_14_0_arm64.whl (660.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.40-cp310-cp310-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.40-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.40-cp310-cp310-macosx_15_0_x86_64.whl (662.5 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.40-cp310-cp310-macosx_14_0_arm64.whl (660.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.40.tar.gz
  • Upload date:
  • Size: 90.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.40.tar.gz
Algorithm Hash digest
SHA256 e6d3237f24c5ed126d1da075b81a430b2fd82862f27f9a2fd241f7750bff9edd
MD5 81b50d7de6d1058a2336ac7378b16f2a
BLAKE2b-256 a5f911a8d6e8c63c90a76f9e7acc481ba0909f5bca28c3b4498827e126a3b528

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 baabf55dbfccf14fc12ee9b74e27367357f0452ea337af4b056a9a30bbc14c40
MD5 662d3b62d07ff222403ab72e04fbbc33
BLAKE2b-256 6ff64e85569972480c7edabb2b27c6e2159b5886ed251ced2a88571671e26503

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 250c33255e7de1c122256cbc5afb959bb273b9d4eb94952b6c60ede364e965de
MD5 c370b4eb64c9a1a3d0771ede7b5b1a5c
BLAKE2b-256 98c169a838f6323aef974a27ddf4c28514cb7a2b09e4802b404f52a9f84f9ceb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 da1656cf8c2204d114627eb3e3e7e9d461c87823ba0e908c9e49b4b5560e2ea5
MD5 58a069776ead234e91466c28759f245f
BLAKE2b-256 bcff43e70fcf480fdf9d8e1d3da574f4ce96b38b403cd123e8fb69acf96bd953

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5cad2f971f26b4fce34d27ad565144e179d2307b333c3bc100c9232e2e4702c3
MD5 013a38f6569ad98f7fca0f5e51c61f01
BLAKE2b-256 46d6a33f9d7a2ab3bb53c3b83ef6cf32da29dcb56e48b90cbfd3eb6931aa48dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b91786ce9d3943b51dc647209d32995bcd1951738578ed8c0a9c73f579b5a201
MD5 c51516b4aa18754853b9b14da663a3d4
BLAKE2b-256 e8f0c7cc320b4d164f0eaf432b177f5c6c24944a800285b60eb9fc5646ec1bb4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 44efd85f1551500ec09871388edf70b4b1160ccaaa846f1373b46478bc29b3bf
MD5 c549c075ab6d2dc4483a4e2bca631c96
BLAKE2b-256 11e6b31f66411dc0fbc22f5bad5e1b521aa90d863d6a5602fe294987a3b3d92e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a213237f36828e1855e8da3617ad8bc00a7ac175a1cb26ecfbd4d4ac31ad3487
MD5 f70ae44ef08cc8825ce10ce8d3364942
BLAKE2b-256 acd67b89850ed5cafbe961ea378dd9e1391c0e8ab9d4bdd3bffde837ff935b58

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1d95e6b3281ca3268d9a00c1d33e2717da7b842b47838f4f6057d6aaa1f67cb5
MD5 3e837bf0e99df3ff901c7e97312f4cf3
BLAKE2b-256 52a79c9f70b5d68dc788e9a65df8902d6d036316325f483c6339796b7cd5b132

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf09bb93401e82a1c9512238b80a806a6a6105bb64bbbc4f20325ac107af0ff4
MD5 cc2f4b9236e01d8c4e83276298ab7bf4
BLAKE2b-256 cce1b987ed7d30562215fdedc9595adc78edcc713686ac0ed5ab994d8c4f4613

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 80efb2b783e7938fe3659480060e22e87e270caec8aa8582641fb6c68818f575
MD5 f572e08e1217abf81d740635e988ad75
BLAKE2b-256 76faec18eb8a6aca249e3c8e43d35bb4532d4acd224154865d7f6ced44ed7038

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 2112fd52cc225daa23c0c79069d790c57259902f6f7b055a8b99df7c14b1e0d5
MD5 24f5d469b870ff854d3a7e6d9364fcbf
BLAKE2b-256 f41606126f47fe81f01c204a96ef1186118136c14aafe82a371a45cfb202213d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6c98964b393711f9a6b0f0c143be02451debdd3b09df6914e2a14e6812dde0d7
MD5 1504499b9da12daa88fedb0707452545
BLAKE2b-256 d65850cfef7ecb398317ed44032fd2e42ad6ebf79afb5f51b3307dbf564422b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f01520339905ae03e1aca1e3f3112f1486bc4e69d0a9f90b5f859329333c8cd
MD5 a856338a8e5d29dfb9a586af418da3eb
BLAKE2b-256 47df3e55f1c6e915ed833fba6e943d40cca50ebbff453f8eea1896675b40eb10

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9ec69c879d0033795682d0da6a0e20c95063a6aa3fb4ac5303c9568e123f9120
MD5 98ccdeaca2f10a5b9e06abad5a006ee2
BLAKE2b-256 2cb5609dc842165e6dc5eed6d236eb0519eaf4cf13b27799f7bbebe9b83d4ec5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5aaf88dbdecb8fb460ac12d4cb862acaad32085d4b5c968797949b228f6a98ff
MD5 93ae451826057e07edf717d48d81eaf0
BLAKE2b-256 86ab5a4ce475c60e5d6731d6da2d325df6fa858cef2cd5fc53deaa6c11561597

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.40-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3d5814bb43a8ac94218934d5d9b4fe2d85520595a1acb070481b2be0655639a4
MD5 f0b5e5ddffd1bba4d17e8259c2666e66
BLAKE2b-256 45ebea75a9278f5b617fade0b42e163c32d6d35502fb7fea8f69aa8be3de645b

See more details on using hashes here.

Provenance

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