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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.72-cp313-cp313-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.72-cp313-cp313-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.72-cp312-cp312-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.72-cp312-cp312-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.72-cp311-cp311-macosx_15_0_x86_64.whl (664.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.72-cp311-cp311-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.72-cp310-cp310-macosx_15_0_x86_64.whl (664.7 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.72-cp310-cp310-macosx_14_0_arm64.whl (655.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.72.tar.gz
  • Upload date:
  • Size: 92.4 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.72.tar.gz
Algorithm Hash digest
SHA256 e3571e3f53585a9e50ba16d5154926ada9f40ef5c508facc6d5d7decb4c1935c
MD5 f9d9f9283df3904679739034efc8e3d7
BLAKE2b-256 db4d75af6a39d54c3b680375351c32514d340f6d458dd2496d693993b34fdd47

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ab496ef7efc234ca0c0e18953cd8f3333a459061cbe0455db3fd5aa1341b0584
MD5 0b1baf6bbdaf46f6fa46ff6a8fa01fe7
BLAKE2b-256 f78ed8c49b857c012b290b256c026d6c0815e0f62fdc11e7da4b6e0956e4d74d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 89c99ac6e508bc9178e457cff2bceeb1a61dbde9433277cb90a72eff3623cdd7
MD5 1b6d38c6ac8141d0db54981dec3642af
BLAKE2b-256 a006138bd75b093df9d84c01d00312213e6387b9e3bb9356cc37bff1114fac6c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c876f1ba0e57ca50f32063249e5cb0040810f47ab8f2e13e3c4e59cd354888fc
MD5 4e4d6a87ad15d6970f66c339ab9a1eb2
BLAKE2b-256 c0cd87894a31170f2bc2c697ff3bf0342c3ff773d5a8c04405f528eecdb9a7f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a914a0665db7f1fc81946533ba539b80f890586b6fbd9ef72290448ac0c6425e
MD5 462148c2cb5b5d0c9b9d1dc50d768b91
BLAKE2b-256 5e87e9fac8e518fd7d01d31ad265448b80c6b31f64778329bacf8a45fd13080f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2380b2bafc7ebce75492a5dd86f8eae181265e37bf917ad0542f534c15c64786
MD5 fd7d917868e91c09f6d9d223db2bb180
BLAKE2b-256 77a66ce763c48fdc35b11073bd6296d16648bc00efb4c60a530b0dbd047329af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3cd123875de43dab373f77997ae38a3ec5ac2830d4e8188e1c07d10b004dc401
MD5 02045f44962ba33789324f6af1f01442
BLAKE2b-256 5a44413e9fe3f022ae660d617c610e27b70d7f4e2fc8cebdc635067cbfb3e484

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0b52593276443b45b99cb9d7c30952e9c81031aba0177ff1877850953bdc651f
MD5 56bae9ad9e20b09e1229ef5dd6d3e7a9
BLAKE2b-256 cfb2a19d3906fab8fc73f9a870f4fe0b064572f4a81131ec2f88247a94823a05

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 91113c5c645f129d601eea7ac46e0712a3ebac41ed5fa22f95c2c89a7ce4a158
MD5 1c76806f37b157be602f017995184f02
BLAKE2b-256 387ae85e9c92d469bc93ffb6a89231ae0f1042fb2b84156f98bf261c685bbcc2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1c2b3a5c27d9c07eda1282321c407ec2084ec926f71358975c3da0b30b37875e
MD5 c0e6c16ec46d1ee039347a028f695d27
BLAKE2b-256 27a59bb46bea45156d625de17f9160a77644c7084c138dd87abcbda5583370a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bbfaa549798aab3754029b2fb76057acc163d12b5c7f04db1b0dc712ec0dd208
MD5 58383ace23ec479144ff99bfc8a0bad3
BLAKE2b-256 7191e4bf63a007a510898e105d9cdace6927892cdefffe9edbc875267839d654

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c4bad966409d6bb23f0ce43899be339662b641ad96675d6e8f197096322e3cee
MD5 14746939402ab8aa840112557bc81995
BLAKE2b-256 e0a727a3b041108c156f0610910588782cb43f96541042224d9725d432d888b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 56dfffcaeeba85428de4924e7d76b219e2255c2fe3ee2eb80a1931079c593d1f
MD5 0030d229b10fb58afe539932e6e03400
BLAKE2b-256 5c04c4875bd37508137e8083518a2e1cc07e2e15118f49812959141d064c7eaa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb9f790365fb79c16b22836c72dfbd1e482e1b78ba3ffd17d94c9fe4ffdaa7f2
MD5 663d4ada3d77805ad50e7414536c985b
BLAKE2b-256 0bcdb71d72881db97c6760e2adad80cdd14e816290a6cf1f07485682d52db48e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ddbc9cd548e5096fd0a3881916ed4fb263d65f4ed6d1bbd256e290d3427c55f3
MD5 3eee2a05efa54dd71a0df7c2eacc542b
BLAKE2b-256 dce0b22c21003587fc94ac91c42df8f84f535058989c14230a10d3ccd61c0c16

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1975fdd1ec6763ec32c943b6f11de965c2f58457d825b53532610b085f48a537
MD5 be5cf6d833ce02e30324288ca22da99d
BLAKE2b-256 d70c945d3b946c8f0b60c403b650004317168b8115a01bbaae0e4d223a052bd0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.72-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a04bfb485dd93a1094e2da220cdaab1cea9335fc84df491cf92443113add3f32
MD5 410753c508cdf798b77ce04b4ce5bc6b
BLAKE2b-256 317a602a6db7ca88f4e9045279569c7758ac0478ca5b522802ff63534401f5ab

See more details on using hashes here.

Provenance

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