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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.48-cp312-cp312-macosx_15_0_x86_64.whl (663.7 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.48-cp312-cp312-macosx_14_0_arm64.whl (661.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.48-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.48-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.48-cp311-cp311-macosx_15_0_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.48-cp311-cp311-macosx_14_0_arm64.whl (661.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.48-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.48-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.48-cp310-cp310-macosx_15_0_x86_64.whl (663.2 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.48-cp310-cp310-macosx_14_0_arm64.whl (661.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file hogql_parser-1.3.48-cp312-cp312-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f4bcd1471337f103e04fdeed2c6f6bef999e70a267cfb58b9df19c64a158b8bc
MD5 757db3456a4d7beb7ef2452c5738f265
BLAKE2b-256 c4840c1ab7c98fa9d9f70b97f238c55d1fdfbf119a28783c474f2af43b40706f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 73105c6b156e4c390b72d6899a03adf0becdf4af2d97cd8b832a69c111f45792
MD5 9e0f2944b45bc77b2471c872f9957631
BLAKE2b-256 beb13009d9812efee079e436476aeeee9d59dc75b5f500f8dcababf4a5d5fbb2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 51c7f07e821e6cdf75ae9fed33dd7af0fef4d6725a010764991d58453e9a2cbf
MD5 e9f6d7c82958f262801c15bdfb3993c4
BLAKE2b-256 000e9dca9d7188ff647d028df9c32ad26fbfd2086a81678e6177491be8bf2e1c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0cf2ababe1f6d20e2d7c734fedb28c9a89d89537c2e2b3061de6af70f97077da
MD5 580acad764b75ea460938288ebe008f2
BLAKE2b-256 29a2efe5bd22ff3a28675e8081869d4c5bac122422f50cf48f291fb58c575fcb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 aee1025951ffeb2f5c80b52079ef978cc88be4df092cbd9855bcf50457d0a336
MD5 7f2a508b110652cc790b6f870277a127
BLAKE2b-256 c5337e635b82457841e18bb09626a42997192ddbd154e96cc5deed3332aed7af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e73f11409097592da932ff695e6f2640ccdae2f17ba1f9b0f8f5814da714495b
MD5 70180645011e955344fcd21e082e87be
BLAKE2b-256 5296f3210dd1f898ff820f0eee6e6b9687f78830bf206eb0f33f5f61e89f4f4d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 180409140c6307ef76bedab2d7690b828d565583678b84d2f90d6e3166fa94b6
MD5 bce8d52b790cb87d1f537d67663ba499
BLAKE2b-256 fc684ab879f80eed5840d36ed32aa8e52b4e2302790547d7c0ca807cd2d36568

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6c541f01dc4c15df178e5617794f8468bbe3ceb89661671d62b1765684ef378d
MD5 f8556b55dda43c8dcc148185b964210f
BLAKE2b-256 0be470b3dd1f7b60881a6f371a5fe01f44e33498675aa31a99d079c40242a8ba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 66593fda9ab851b1f92cafdc8a1d2f7b7087273a4fdfa0c3be878bcc571ed2fa
MD5 86ea4ec90cd272d114fa1f180b4a7cf4
BLAKE2b-256 22d68bc03155a94dfa3b86399522b24c09dfdf5764b0146eff25fb7824b45ad1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 81d2a8cc267ab0ac4f48b1beb4f599d1277bfb41ac3121a3d763437ae70a99dc
MD5 186b6e3883bbd25dda23a020f126b6d6
BLAKE2b-256 3df96fa7dfce8729211cae25b807879fb7663b82056fe566db19ebd2fc085e5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.48-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3c8e15ae17e83ce77262cd786135b7a5ce75ab0158dad6da410f42f4220233e7
MD5 de26364df2504fcf3bd749f4ab6af993
BLAKE2b-256 f4cbf0f381dc75ab7701b28311e457d94e9a8092c896fdc2097b482c4269cbb9

See more details on using hashes here.

Provenance

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