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.35.tar.gz (86.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.35-cp313-cp313-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.35-cp313-cp313-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.35-cp313-cp313-macosx_15_0_x86_64.whl (652.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.35-cp313-cp313-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.35-cp312-cp312-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.35-cp312-cp312-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.35-cp312-cp312-macosx_15_0_x86_64.whl (652.1 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.35-cp312-cp312-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.35-cp311-cp311-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.35-cp311-cp311-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.35-cp311-cp311-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.35-cp311-cp311-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.35-cp310-cp310-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.35-cp310-cp310-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.35-cp310-cp310-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.35-cp310-cp310-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.35.tar.gz
  • Upload date:
  • Size: 86.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.35.tar.gz
Algorithm Hash digest
SHA256 1809da3163a436e9bb8f3a72502ec43b286856d1d0bf6f043ffc01c0fc53f0a0
MD5 463e82f296d4f71467c4a23c85f00d81
BLAKE2b-256 c3a50c7fb59774fc132ef8863f61ebe910a33a8613c41f445550d84c1ad3bc21

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 15bdf00867cf4d484de435c012b997bbeea5eae294ebbc00dd625e4e70276ead
MD5 cd3f9290310db61f34579521d9d5931a
BLAKE2b-256 a3b69d2fbfbf0daac6ab83c49ce024afc22dac92cf5625791dac1969dd93c3a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 126d32e0c87ed64543cb44916b86b5d8c9dc630a6dcb4a0d8d8365968e6b117a
MD5 685b265821bc7ad4111d52a30f4e965d
BLAKE2b-256 639b152009d75169daf3c0808424afbd08a6a0ab6a3f4ca82a08f153ab0e432f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b5b08594a27dd883e778ddf04b430660a1e2a99ef6ab54758886e511a54af95e
MD5 5cb017df9f2a26e37c900b9b501ee245
BLAKE2b-256 9d3b77d707766c21bfef5de64a0283627e5ab5d7f1695899554308d4d9d90c87

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8e4f32e576e86b25c00294f19cd27ce38149c9602fdfaa5debc865fba8a5f30b
MD5 8ddc204c42d7201ba44f7c82fd29157c
BLAKE2b-256 8df49dad0c5399a5d46d161af8469b5257d17896405b017118a42cfa94d84803

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 feb81fc25434d7cbbf13e17a376a55a35d23850f449e1d56610f25682a76de48
MD5 e88f766079f2de3d7a65b85024a5672d
BLAKE2b-256 4db8ba1ce831d2b223ef5823b828f24556efb9270cc933eeea253e8eb4c76ca7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 37d6b1103ca5bc0f8250089aef2d48f49209fd2643514a382feaf627a0bee0c9
MD5 44df674d5a34927a5beeb18fb7d94d61
BLAKE2b-256 721ffc17e13204afecfb5f1f48d3bdb5be633a1391b2f55d4b50a6cb4d42f03a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 10152f8c497742fb12469da185c9b8af315b154686367d1bd0bc4ccd7dc60b4a
MD5 58290c24c3ec817ff88f95f7bd375431
BLAKE2b-256 2d362737f395df980a33a39708d82d663d9a36d6f31ad88e838a370311915e52

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a869aa56307bca841197341dcab21b137e331abc25fce0da8365ef8293707155
MD5 a8b5e5dc881722acd9f57d5e13fbdac5
BLAKE2b-256 84a51217f381a2acd2581adf18d478da55d19b4ca51ae0a553a846f4b173f89a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f4cb47a51ad890a40421d34155ff0be88b8520661d945a65c536e20f533cb8a
MD5 39867009f8a3046e8efac228db2b4365
BLAKE2b-256 f0fce2ee957040449e9a2598c76949a3f79caa0368bfc62fb87f03fcc437df42

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b16e0ddeca18fd6e68318b284e15bb7cf50c3cec5ac355a77614bba395757d2c
MD5 b5c7784dda8e4cccc3a06bd00ec6a698
BLAKE2b-256 6abca091851a7dd89a6c7548d44b0e7aaac32bd58784ca97dab177c2adeeb5d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 99984b6cf6d91a31908995b95dca23a54288fc7d2bc7022ffbdf4f1d1583863c
MD5 a37aa2afe13daaa36568e7df176c800e
BLAKE2b-256 3fe780296c7d7df750d94981745cab635d8b11edb0b632b315a358ddd7bcbe42

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e06f2963360726588331647cafb259ec25c5b32083c3bf994ecec82c506e7d44
MD5 2f77a574715ca59d91b30d47dac018e3
BLAKE2b-256 4c7985bd34624b22277df23898138d0898de2f8aa3af68de1ec9c1642fe504a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b946f964512f9456dd9104ee1088cb0433dffa03a80063a4fc83c1eda13b27c
MD5 bb317e8da918614ab55b2b2638ff1cfb
BLAKE2b-256 9127a1d3c6b0fcd7514fd03552b0170b9ec011b5c885f14503bc9249c27d5839

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e9409c44627e28f35880270043a837f85e04b3581083fd2aa5a0c257d1e53e1a
MD5 f9fe523598f54d520d2e0d79b498f503
BLAKE2b-256 e147629cab7a6b0f29476a9381ea952b262454a72a823eea5bac06c8d71ea21b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0bab43745883f1bb920ca18a0de1fd67f0d7fc1bde6e4ba41fea68ad01a18fbc
MD5 60898f22f407942616ecb0c261d3a978
BLAKE2b-256 f9c6d21c39f91706afe8f5596145a24c6c58ff40a3b9ca596fb7376dade32e7e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.35-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5d83b0af5b68e9d79305de704802a14bbd4a76033cba342621108698d197e1d9
MD5 2bd652a912a9ba7784d05eff6805ec27
BLAKE2b-256 cafdfea415d217b8523eb2b900d1fc32ba653177a894c6490ce8a6ef814ed284

See more details on using hashes here.

Provenance

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