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.38.tar.gz (88.7 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.38-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.38-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.38-cp313-cp313-macosx_15_0_x86_64.whl (659.7 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.38-cp313-cp313-macosx_14_0_arm64.whl (653.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.38-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.38-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.38-cp312-cp312-macosx_15_0_x86_64.whl (659.7 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.38-cp312-cp312-macosx_14_0_arm64.whl (653.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.38-cp311-cp311-macosx_15_0_x86_64.whl (659.5 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.38-cp311-cp311-macosx_14_0_arm64.whl (653.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.38-cp310-cp310-macosx_15_0_x86_64.whl (659.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.38-cp310-cp310-macosx_14_0_arm64.whl (653.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.38.tar.gz
  • Upload date:
  • Size: 88.7 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.38.tar.gz
Algorithm Hash digest
SHA256 1ff1efb682d04d94d9db00f989608c4a918b129c0998a93e7a7f0b2331b59359
MD5 b4888ac010c3cc715eda6ed917b6c480
BLAKE2b-256 e9b5fb1ca364e80dc3066048245b3ab490916c37257a16d697d384ecea63afb5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d45f2f7c945f20f68b9e222da871d07c7471ecac22897fd1aac1819c2d1af16
MD5 0b69563bd7f642f7b1f74aaea6de992d
BLAKE2b-256 3d60a29f0bf4449cf108c1c1ffe6b9680e7e465623566e04d9862890455a8264

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f329c625c728cdf9c5e0741ced1b87af02301d356819ec4aff2cb4e4dde2b15d
MD5 3b5f9bc16b67627adb863de707297c4b
BLAKE2b-256 8277a089a5aaa6063a8863dae30a44688bcb5339a3a81dfef17bc286bb243438

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 74e9be4c04ae05f1aa1b78333d35afe6f3f9a926df46898551dfc7c52e93dddb
MD5 aaa960bec7727ffca2b304924bd4ea21
BLAKE2b-256 23ce5a8e8f6c30d6ba9b3cb5c18d038c189a2c92f824a82d7e6f321ad24b48d3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 12353601a108377db966c2b90c3585d78d76553c77f3821cbe49c5615bf8e2d1
MD5 6c25f445fdd48a568a541a8f0257480c
BLAKE2b-256 269fd26052f1edba6812a1564b9ef4ee86cd49849109662ee24d2567c775d547

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2e8ba4d9f03ce733e49becda43923e3a89c36fd3564c62ac55db9d6712c616a
MD5 cbe157fc2298495aaf9c9ad5a485c8c3
BLAKE2b-256 926e32d21e33dd9184dcdb4806b2c26cb365d537ee4a071a38f6443a0838ef8e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 95fca76b246364683f90bc603e1762aa7150e4acb9c5fb61d27b87733e4bff7c
MD5 d5cd999945e9b205321d797d8d6889cd
BLAKE2b-256 c35b2ba9e9432b6483c971b11ed754c880ad5c43961c2220ff431dff68038de5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 9935708aba669d4dc3fca28abe8b7d5af144fc5cb10e7f4ceb435f354b666837
MD5 19f06cb21031bda78a5a059234fd96a9
BLAKE2b-256 1545af91400a2f09981fa0be6e46ce8afc913ee852a3a7b58dc65eac4a6b65fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5ec9613ecfce170e4ec3e0391352b9f3e96d545e22bda44549f05693789e9ca8
MD5 a1766742162349cbd969a6aec99ca647
BLAKE2b-256 517059a094abe1a5aba0e2aacb403809d98610d0d30ee61bf15f8ccffffe4f02

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8f1eaf55b21ab20c8632a3a4ff53dbba2542a19cb6638daf26e31c9efbbcedeb
MD5 cc1c2a72d07ca3172a23c80d555da9f0
BLAKE2b-256 bbb3ae259e06e22c87610a4f55923de1551268c33551730705ca3343782093cb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6000a6066e652f13e033893fe877ac0d95ac95a161e3a206a270d423b632f21e
MD5 0bd269fc1fe42c21bbe54a5f0c24a07d
BLAKE2b-256 ae47a1557c90361df864e4d3de66e89a2816e263637ca90866bf36a9e080c058

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 521ed0f0a6f61bca873cfb9b51c9073f2ddd2c8e730e0affd4377b6ddf4170a6
MD5 a7c9fe04e5125445728d245cd48e161f
BLAKE2b-256 60202a7cb460629878445d9a928ccbad505a66616d2ae7e4a89e962558f21926

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1a6c8bffb96c50002d5ec208921b654903af42178cac5d21edf9e4284c7c3104
MD5 ffe9ca349219cf1b9dfbfbf0160bee79
BLAKE2b-256 9eb471307055b69870e847aa713af7f273969634de698dd99abadf28c84af96e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 112c4af4fb6db704847b36a3b3e8f8e538c52813bbc97595629274ea7f06ee55
MD5 b29af35d4d271e800199138894b3de2b
BLAKE2b-256 fc9cad408b8fda851ab25add9a6a98241fbf1a20f9945c6c72394d3b5798079f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8bdaaf2fcef4934b27a2eec1f11aa5125550d1b9577fc39fa8c16be184dc8a2e
MD5 bd7222c74466f69e98b12f12b7aa9bab
BLAKE2b-256 b9e3ec5f331a18cd4680626f0f5f08f31d4fea4fbba91ba5fb5afe2e3be7cf64

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 43c84ee38e5c5e2744cfae215a402b506120bf0230dab53d9eb9c9e17a6ad201
MD5 eed21d310632a7377b02e3fae36d615f
BLAKE2b-256 e9af283ab82eb93b2e6a2e34331c221d80189e799e505873dd2e279253c5d8cb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.38-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bc8b8ac9b312fe787e1bc50652617beabde007f74fe6c8a7b391db1e65ffeb42
MD5 69e46d4277e9fe4d788c62b4e177caef
BLAKE2b-256 8637b58a39768431717902b9dc343d07ede9415733ab5278bec76c33dcc2baed

See more details on using hashes here.

Provenance

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