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.74.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.74-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.74-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.74-cp313-cp313-macosx_15_0_x86_64.whl (665.0 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.74-cp313-cp313-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.74-cp312-cp312-macosx_15_0_x86_64.whl (665.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.74-cp312-cp312-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.74-cp311-cp311-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.74-cp311-cp311-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.74-cp310-cp310-macosx_15_0_x86_64.whl (664.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.74-cp310-cp310-macosx_14_0_arm64.whl (655.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.74.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.74.tar.gz
Algorithm Hash digest
SHA256 777a18d69bd0994b3b0ac1c75ff21eb1779d1a5f8e80945fbfd6c0e1cb88ea7c
MD5 4ebf7484d7c6d0ea42a01ce786c138ee
BLAKE2b-256 2ede0dbfa352455acd57670a085c68b4509d252be7fcb6915f6167d820d8b4b4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8bcc4fbdb378bc57ce5c53b213dec9c8c0b286b7ff647a25ed8df4bd542890a0
MD5 cfb449191406b87a1274fe23c879c4de
BLAKE2b-256 e0e9c9421223e5001505ed07a8264883f5473ba53c3a73e5cceba4649fbb6ff0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5725d98bf8af03a2363b8334bb0440cc274bc3b074a2ff636b8411ed4dab7ae7
MD5 d28bdf35039f604b393dc2f4c56a5c99
BLAKE2b-256 7e5b971b20903a1a7148a0ee1883f7a0836da023edbe9b0336c9397b7b1a4fc4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5419734e5738523bde9ea46b0162bf2521a7fa9025f9f31008df856854f1e427
MD5 e6d34bf67944ebf2cf7a4da41c14d038
BLAKE2b-256 2656eaff7ef52c8c2642fc67fd3fd99dcb986c5c7f7a6d1ea933a4b0b755b7ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 93ee57afe7009a5ad7ae2815496685fea9b067b69d50d154ad8238eba3d2df92
MD5 aa84715b31494ff370c04dd36bcaac7d
BLAKE2b-256 c5742350b0f3dab703ab64fb257a7d88969eef005f7862be53f6ec796b4d9fae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 725aefc3a46defdfc202889ffe80dd73da1a5d919e1c0b42d2fb26b7733bda82
MD5 e31dfe6234dfda70d7b043cc4a36e53f
BLAKE2b-256 9a72d817cc19da58802a2e4c05568342ceace4a49ea2e1d5b79f07181fc983de

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 47fcf71ce9fb9bcb08ca5fad73f5c34ca896705e8c48a8fe16fa0a9d70bc6398
MD5 47934686e66a73f3a4151d87635006a0
BLAKE2b-256 2c42cf6dc8cfe3986ea9174b9d2f839af75b5fdba969e3c546f51caef0c96e3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e502cfc9db380a80e830b48f011aa6b369563288726a28d910a43c9e65b07037
MD5 ae1389a3cd09011651cc23fd51eae605
BLAKE2b-256 66fd6b591b6288ef6a32d2da6a1e4f491baee987706156854b34efa5f988156e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 25e207f5c1ab56ac1b24f5f2e21c17a9dce19a92fefee16c091ac1d7982be0c4
MD5 73a52f3981fefa647691df619afc4e99
BLAKE2b-256 01448902bf028005f05df78327fe54cf2ceed9bebae6d4eeac67b3997d33cdce

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bb9e70e357d43bc7036807cf84ae0b4e15d761a4921e8fcc6b5601744f3992de
MD5 64fc006474fb80408089bcee1a87ff57
BLAKE2b-256 22fc432d075d444b903b55c2ad98e945a1fd63a83599c09ce33f064b73ef2d7d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8341847dd0b8db5b0d4e1cec63486c555476353be97aebc0e7dffcb8f4c1591a
MD5 9a02ff9d0d679182c743de582e6aa796
BLAKE2b-256 e39c3af9d4c303d22e507a053fd9042e77d5a2391c8278268c0ffa00085439da

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 415a2f2dc2a746a1fd5970e7f266b56c6ad86c4c181fa594d6a1d45bbf5bc415
MD5 aec921939a250a1111ca90a2bb5723ec
BLAKE2b-256 60e53a622b3089c8c1ca0d3acf9d11c99fd2a7d3965821ee31779c4f345bad70

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5041c4dd35d6d6a35624827e6953d2798c5e050537e4f5c484f650f6df320c8e
MD5 fbba70ee8a8cde0322f40850e2c325a2
BLAKE2b-256 dd9c5223d4dadb3ca5f1afe22cf9e54ac7a95d72e312f74c19b89f6e9b8ea65a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 333c737088acf6167492893377333789e67082331bf58e02d54a464a0f7b8a82
MD5 d6458563ba76271c8969fcbb93bcef0b
BLAKE2b-256 3dc8c8d508af3a09bfbf01f7748d3ff90f970e36bcc211e9289051ab530e6900

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7733ea10af8e2630f129ffa43eedd961ee208b2e545e3b40654168e48e39de0e
MD5 e3aeb7a51136ad4d40f0b7c2ff5c9a47
BLAKE2b-256 4de05d3bdb8f2e9480fb2282b19977f549f908b75a1691ab7632af749631c7d2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ca43d2d99168c2d6e0c62f3afcc692e4d71e935da7e9889d1cb5dfab0a0b92ec
MD5 f163a13496f2b15986a3bf490e0d2af4
BLAKE2b-256 c655c0c4daca95dea06fc8f79483cfd081f92a73418b8f5c9ce43f86146e23a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.74-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2b5b17cc953116046c8d4d7dffaea5cf8c50f28770e03931bf63ac819e3b1804
MD5 e59655f37f586f0be565c433a3787b4c
BLAKE2b-256 42a890774d85ef67b24e6827d9995563db2664910ed158f0e63743df11af6660

See more details on using hashes here.

Provenance

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