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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.78-cp313-cp313-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.78-cp313-cp313-macosx_14_0_arm64.whl (658.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.78-cp312-cp312-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.78-cp312-cp312-macosx_14_0_arm64.whl (658.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.78-cp311-cp311-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.78-cp311-cp311-macosx_14_0_arm64.whl (658.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.78-cp310-cp310-macosx_15_0_x86_64.whl (668.2 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.78-cp310-cp310-macosx_14_0_arm64.whl (658.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.78.tar.gz
  • Upload date:
  • Size: 93.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.78.tar.gz
Algorithm Hash digest
SHA256 de5dc8e06912e5333fe914974802bd3fd09ab5b10340d6731ee8fc2364213770
MD5 f6715c10269e4ed9525c13e5bc9b989f
BLAKE2b-256 66afdb9519fa0d04209fb303a0cce1c3ce6bd8c230dcc5709274dc36971b21ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8b371f9a215d2398a29ea258425fb5d31b736ba35f7f0675ab0b37a66ada43a8
MD5 94c424e833376f7cb3adfdf4acd27555
BLAKE2b-256 29cb5652169e9ef57b7b48cac5f1b91e12ae97aaf524f2b363474959ca142361

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 af3dff1118c40fa69800de672dddc58cab6126306b3d66882b40ecb73857b938
MD5 5306e45dd61c400928a3b4bec0eac937
BLAKE2b-256 0a52621f0bdf9cf5e8768320e65f6e8a593a108cc337be20ec2bbe215b12c1f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8cf60e9dc4676e85b22aa9764a99f674bcd3fc4d2aca57c06d746a4489b04c74
MD5 f0695a541811dccf49feb933bc6134a7
BLAKE2b-256 84a84e860b0ead845773d41a285d27d5413f3413a93dfc8fc5d806fbc19f5e8e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3b946910eae1ec0128d59efe4c360ff63b6cd0086e45a5fc09339ebf77e26684
MD5 5156c7721d622a7338d061cc1c125da9
BLAKE2b-256 ae2925a34ef99ae6ce073214300b30eab8553c66bed650632d1cb73eb0919f9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a481d1e1e492a7adc8dd3a150a2d22c5d9b773a2d79dfec5fb3a627169739c2
MD5 5efbdef911d5217a7f1ce3d0e1252843
BLAKE2b-256 cc5456a81461e0703a90c3da94d63a13aba2e62047d880193505c77f9cc74add

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 421afc7b1b590eaa8fbce9416dc395bab98fe2129b865cebd2cd31202f368e8a
MD5 44330b1582db1444a6604af385bba440
BLAKE2b-256 b18f9148ce2fc0c75adc59188cd48c64c52fc68a980182cfb2ffa8e88771479b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 715d4ef2f53c5d709a682905c850e2ff6f28f908f749e85d2cc9cd4e19f3fb1e
MD5 79e88b243ac448b5063295506616a2a6
BLAKE2b-256 2063c56e456ae7e1e967808f294eb70c3c30894be32ab28faecf353359757b5a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bb6fd6234774e418798ba25ccc8016d8f998e4a55bbc413a1fb14624c84f3407
MD5 80fa4216a85636596ca85e6b33effeb9
BLAKE2b-256 df5e6b6c8052abedf462ea3c787fa9a5f84b7d5fd0f0a2d85e8b7c64de9e54a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b2c6e37df93b58da1bb47d3550725237e1e3cc8d33740fc12dff3de92e6fedef
MD5 2343323b199f913d66db3af9173482fa
BLAKE2b-256 d1418647f3d0ca931469077f13ecfc6abd3fd92062dd3366dbb71a671c9f39aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 80861f00df7ad6f3bf570b3b95c00ab078089bea47bd54f444433a840246c41b
MD5 12b3c690d73da8a2f5c634a18d4362a1
BLAKE2b-256 595da1c9a616ec1118a2d6e163862be1caf5b3f31679734a3dab965b1bb8d363

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 048f348bffec785d69ec477821cb2345d168afa624dc3f00f2d9bc8d2ef61a53
MD5 b26634bd7b96be9f00a21ecdd6b40c30
BLAKE2b-256 4b97e4a7b2670148f8c5af3ac5d7b091a69f5cbb7e8eab8260258475b9d0c7a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7f7fbbdae20db6f091be147025ec787e790c58288ee6fe54300c6d6e7958838a
MD5 8a9ac3e8a3eb15a7c29081b45a52d283
BLAKE2b-256 43a9dcc0108441a8f649287c4b20501de83f019fb33284cf341a8b5e0f261157

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ace868e51eb9a23d833a63fe7f62a2296c602353f2863ee0d0c6115f06025915
MD5 ded8bd53b915451e85d16fc53d53e3e6
BLAKE2b-256 de9388d9a97454c666018a66ffaf4551b2eb624d17044bda436f8633d48ff74a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 620e53825da8955ba7bcf7a199b8bc4c205bf18e74a892a7a63d1ed5454e1c17
MD5 646f61eddfc705bc2af2c0e598722183
BLAKE2b-256 41f0f475cadac7f994e8295c76ec76106cf9c5563f41f4fe12b4c6980856adb5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5e457d0590e96aa89d7b7a62cd17a37d5f3e83725a8d19202a183d1d5c666670
MD5 4b6d4caca2f1e8c462ad8f7ed236bfb6
BLAKE2b-256 52a3bf86e1305fd42e13cc2fa31833f806c83a25bba42ac0224472a757408940

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.78-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 20b78342720db84dc2034b83d2a853a9a0e5044266167a8e31822777fafd5bc4
MD5 c503605b7cbb28b7089a59a5426ec906
BLAKE2b-256 8eab6efb85077ed5c7b5445acd781d777cefe77eec90a46ef3c168f2d1e9e04d

See more details on using hashes here.

Provenance

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