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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.49-cp313-cp313-macosx_15_0_x86_64.whl (666.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.49-cp313-cp313-macosx_14_0_arm64.whl (663.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.49-cp312-cp312-macosx_15_0_x86_64.whl (666.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.49-cp312-cp312-macosx_14_0_arm64.whl (663.7 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.49-cp311-cp311-macosx_15_0_x86_64.whl (665.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.49-cp311-cp311-macosx_14_0_arm64.whl (663.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.49-cp310-cp310-macosx_15_0_x86_64.whl (665.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.49-cp310-cp310-macosx_14_0_arm64.whl (663.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.49.tar.gz
  • Upload date:
  • Size: 90.6 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.49.tar.gz
Algorithm Hash digest
SHA256 7603c879d68994dc0bb6b3511833c1721c6828b546322fdd820c90b1efd8ee28
MD5 0494f03f030b4ebe2b2e9aab05206f9d
BLAKE2b-256 c4c648c0ab6cca5aabf82e3164b29da1d82bb0cf1c7a47e77432c8d20d4ac49d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65d4429b0628cfe4eb3cc4df6c079838fc3bdc17361512e158b55776ab896b21
MD5 1b5e6d5953f6fcf62244107e5a65f619
BLAKE2b-256 28d856e65a341bb6d61be9ded434848cbe0af4e540968755a235b4c6c0c343ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e5cf70f6ff3b5199c6ddc6493eeed2c70759ceb71843034823b4c742b14f9cf6
MD5 bed0d0b17ca1603e0f46acdef48f3ad9
BLAKE2b-256 37e2bdaabde335ddb480c1bc724ff89406ffe439201a3087beaf6950bc22fdb0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f43e2fece0d0bd8f93499972dee7097e1d6ea39cf8fed599a498990c5d744000
MD5 458d442ec764b12402720d9811b14841
BLAKE2b-256 3d0b8977c67232e5b98fb9eb774213ce96fa90cdd0a8d1d2a676c45d26736e23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7230aea017a4ec9faa1c68358ee9aadeaeb453e519545da21a5f93a169ec4f07
MD5 741a2a890d769a0f25915c0fde35cbfc
BLAKE2b-256 824e648d1bfb4c1ad5fe9c8c6d2f3937baaf30b1405c66e37cc080eb460c0d47

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a41f5df521ecb00c0435325b74746cfce337ea34d9d6a0fab48491e6f4329715
MD5 265d5380b636d488d9e2cbcd3c520369
BLAKE2b-256 d0bb9e4d876d3601ecea7d32b1ef1bfcb9d78ab402a99470ef75d65be21f2d55

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4b4fe6be22842b65f015e416c106fedda235b407fa0020fa0b31a9feeeb3d227
MD5 475569d76da7c39234c9d4e2770d0ef6
BLAKE2b-256 acea6f7de90b4aa503feee7ae649f76232a4e8ce06388c0a24b76ff151b727b2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 814c5076a90e4dc77c8c5a272ca98c7128d66cc1f64b0abf5cc12b1359dac44e
MD5 7167b157dab748408346ff93204362df
BLAKE2b-256 99ac3e86a1b0283af35475e0d7eb1ea8392d19c0e322927cfb699d8db013d087

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 eeef6a47e5d8358d7814ea5a1fa59cdae60a7bfc951b03bbb86adcfb9f05432b
MD5 278e415b37a4c5286cea6b7a4c15e813
BLAKE2b-256 098ced7f03387824d6817074d86a91a0285e00ddb39fd9515c9a7b77bf09390c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e6db9c2b2839c9f0cb7dcceb6ff5fc3a60c16327ba921360ceee4a650b808d11
MD5 304b0acd94377772698217a6991c9769
BLAKE2b-256 89ab6197fab4d38fc65c35864351ebcf37bbb25891ccc6e6acab7de56ec7063b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 df9f0dbaf93aae120b8fde620f86e8af4d499440e688aa2ee0b75851d3fb9369
MD5 ad0b3bcdda88832c06dd0d476c38a7de
BLAKE2b-256 e7e512509e1465efc1d9f2663397dccf290e1ecc4e8f6a4bee69c565e2a267c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 772aa5766f199c66c5dfdfe7336c00c970f6abb45e14b8cc0d25ac090ec73943
MD5 2052de50c9f9e7e5cd022c05256a8c0e
BLAKE2b-256 f8e97e517d42238d426f11f16b184ab2caca5f1c2223fc63d9d8aef5cd296020

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 762191e44eb00b323769de437840c09eaad71adfe4843feb7ae9768c0c19e784
MD5 cde14c4cbb3c5dd33aa9a56819ed2641
BLAKE2b-256 91579c8901cea18f24bfeb401e5f29dc7a895ee9df2c72ef7ea2d317dd4c0eb4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d316d528f071ef99706563c33e2d0997dd430b2a9f5b4fc1c0083f55c4caa5a5
MD5 809d2db66c3d05b788a5d8be0098d9d9
BLAKE2b-256 adc5b8b39cb7aa98cfa234136ee1ed1b2c50faf598f031cfffc21cc16a2659de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4c5f3c1832dd22f6541763231419047558be7f38f56e6caa95c43b47469c5767
MD5 1621ede5c5a69022623dcfbd2c513e12
BLAKE2b-256 7ef32900959b5b5910cc3f02d5a8ddc01ee81d58486a81490ddac3e29cf563b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 18c632667cea8052293b381a69d0a14d09efee994a13cb068198a1a20c28a36e
MD5 ec0843bc0ab9eed152fe54b55163db97
BLAKE2b-256 82846b2554cdc6eeaca0ae04687a79716076db406b877b9942dea49d76fbdd8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.49-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4418c715c629c6b6f1110842b7f6c489cfd013a9be9b79ff29c0a8e034560b8d
MD5 0fdb4517e81078f56b5d22223c739c70
BLAKE2b-256 b3152549d74b814ef983cc81db21f7c284126de303336b87a82a4cc74d66f1b4

See more details on using hashes here.

Provenance

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