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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.46-cp313-cp313-macosx_15_0_x86_64.whl (670.4 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.46-cp313-cp313-macosx_14_0_arm64.whl (665.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.46-cp312-cp312-macosx_15_0_x86_64.whl (670.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.46-cp312-cp312-macosx_14_0_arm64.whl (665.8 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.46-cp311-cp311-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.46-cp311-cp311-macosx_14_0_arm64.whl (665.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.46-cp310-cp310-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.46-cp310-cp310-macosx_14_0_arm64.whl (665.8 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.46.tar.gz
  • Upload date:
  • Size: 92.1 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.46.tar.gz
Algorithm Hash digest
SHA256 2630fb2fcbdb0c8a0819eae4f990ef7005c87f5427e2975b8b793c7667a07ee0
MD5 3d5796c00c0b6b65fac76f160cd010b7
BLAKE2b-256 2f9dacb95207481d40f617d7a83a76991d847642bf463e3557a71dca962a99a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 983f4bdb548f80e5a275a77516cdda31865c6716091bd95049e0483cbf92522a
MD5 8c6a1174796b009b257ee1ed793a2672
BLAKE2b-256 9f6c7efae9c3de872d762533ce66f84a1c37178f62c5f8b6af061c1b0e1416df

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0f60d7ca24f31cba8fd3064722589dc981bbff4ff5bc5cdc454442db3944180f
MD5 ed15faa15e2ff70e1d09be77ad4af4c4
BLAKE2b-256 11e243ab674d2b46df63eab84c525afd81cb664fd33dde8fefedd3b7e61e46db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 375ed74be7c2160e8d751d190dab2328cafea1c75e7371bc691a778a56633ce3
MD5 443f8e47ed3b62ce553faca446748112
BLAKE2b-256 251a0f5942667d0a184774de81521254f91272b8c952f3e0b8f675ae9bf7254a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 227794ba085239a84e03ccd8b6c800a7152ef711cbfb0a09b509ff4f2dab17c6
MD5 00a282cb06293c539f2b2de1a9bb49c1
BLAKE2b-256 ad93d0ca1e72a9ba35663389ec6e321230832486e81bad1bc8276dcaadb850f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4a89342c676a0af38eae4ee664af47cfd58e925e1248b17dd1f9bd2f71599437
MD5 015db0a370707a97979d942d3fc17547
BLAKE2b-256 fdcb35d0ac0026ba91e3b78e4d20f9efcdab003c6961c7b71bab5dd0e09cd666

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 96819aa3eea2a1e5282648e56745f4fa72f1e687e7f1ca7ef514cfefb295c84c
MD5 65414af33df45ce370d2137f19568c17
BLAKE2b-256 1d3e0d77ca5a7bd7f89ce40951841e877933434f5ac28796a5e116e90d3ad195

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e3afefe9e60f96d80448beb07059fac79ca70cb71be5bfff5170f3dae0321333
MD5 dcf2c0bfb39b4ede8028d2be396eb43c
BLAKE2b-256 ded4dc577a14df63b03ae78edf3c63b6d75bfecc05aceca6fbab5766e411d75a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fe7885e6f2461b7bb4d092437e78b50f1246a17e5ab773561d73d180a7f76e18
MD5 1a2d05cf14cfa3a6800d6411cfa28cfb
BLAKE2b-256 3415e022d011215e821ef70b8acb8a8e09445825855482400bd4af6a77e0e402

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b8e19b5bb8ceb8f877e7c5e96d4aa3397c9ad713ee300223f0b4c930c8aae3fa
MD5 4fa27206de28c861bd24609c6ef8a59d
BLAKE2b-256 4e57f4cb52e96a7df65129643a436f07ff6006048223bdec6008293b81010eae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 52ff997b8c3baeac677f93e34c53a31b98143f3df5f1db4ad4f1b5c494cb48a5
MD5 029895bd21b55698e46757b9db3f3373
BLAKE2b-256 a192f9800194a2056e34aaf966e10d81438422f468ee23fd6d70ab60b62a989b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8317256d78d0e3cbcfd9ae31d20023bc28faeae5fdee4d80ce09eade63772d75
MD5 7a32fb17d9dea55dfc5aa3ab88957dce
BLAKE2b-256 4084b343747e60bfa9c3752d09084b808b957fdb138867cbb5887eba08950bb0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8f23f9d38adaea3754ab55078f1924f057751af157ea1f1b46c5b8aff9f7d09b
MD5 714aa65e7da747b25debdc3efa51573d
BLAKE2b-256 9cc3c9be46bcef203bab14894ee9e30b0576b41a6ebb5984438fe8fa80d1649b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0da9e17fc87f429a13678a72ab3f6b62eb4e03d0b1e7ff44d8e85b7fe810cb40
MD5 af852a667ce2bdfab4bbe4bdd528aa6e
BLAKE2b-256 6c6e672acdbaa042f959e901fa2c664ad791eba1ec3ba33a4730c07f218c4164

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9338f7cee90053cb57cb64be16bd46ac8590331e25302363a7faaf0ae327f412
MD5 859bd6005f6854dd319c629ee60ed176
BLAKE2b-256 15723ee6e5d42e4b88faeb1184dc17b4c22a438ef526ae26751d7f38bc6ee60f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3439ae95d2eca80a26fcb54a49eb7188af914ab5fe36362461725d88bd049c9a
MD5 f838b37b95c1b8c89746218c509b924f
BLAKE2b-256 6b1226a4ee4c4af9ff7a57ce26eaf6174746015b909fad67d94465dd8a075d3c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.46-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bcedb76a71cc49d7ffb1811f1455136f61959639899bc2e8016013f80f9e1479
MD5 72e444fb79c20eccf7f3e60f0c6417a4
BLAKE2b-256 89854b2c85c413b0774788e29329db023c18fe59cec6247b8ea0b00b3a14a3f5

See more details on using hashes here.

Provenance

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