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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.47-cp313-cp313-macosx_15_0_x86_64.whl (665.3 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.47-cp313-cp313-macosx_14_0_arm64.whl (662.9 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.47-cp312-cp312-macosx_15_0_x86_64.whl (665.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.47-cp312-cp312-macosx_14_0_arm64.whl (662.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.47-cp311-cp311-macosx_15_0_x86_64.whl (665.0 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.47-cp311-cp311-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.47-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.47-cp310-cp310-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.47.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.47.tar.gz
Algorithm Hash digest
SHA256 2c4930f15ce514b51ece739f185668247d8a845f7e2cf8218c8656090655d5e3
MD5 814ad2b49d441ba30ebd730c96f47c95
BLAKE2b-256 8b9d1bcc7f0bd01deb10e52b135b230beeca9b3c0808fe7bfcfe3dbd220e076a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3a87f588c7a0a4d03d701041e2abf033816e17da5b420f6ab063c7669260d66f
MD5 5a495ccd0e3c113293ebd9fed5b8751e
BLAKE2b-256 5397de8554ee0e8351cad077e63e16823aa9d0e429adda24ee90772a5971046e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4e9ecf6d88b9099ad5d05dfaa0a56764025e216cda5fdfadbcd04750e34a249a
MD5 1a169a43dce7ff03ffb32707198d1d42
BLAKE2b-256 47fb7556088bf00681fda231e1e4aa9b234706a9c98b1c4de50adade603ad682

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 afdb987b620a3ffc502b810f1d3ec935c3211dabce075dbf923344990ea91a09
MD5 005c20c7b21fcec3f6fb4e782a2f62b5
BLAKE2b-256 1207cecc05f21cbe4c0cc918e2cd18939a1e033e13935d04201ab3efbe0a3115

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 aafd54522a54bfc9d3693c34e720c58b64f38e690cf0718eb57c5db5d4a8aca5
MD5 c2494f9797bad06b50bb1a0074ad1e6d
BLAKE2b-256 899866a3b9bade1e66a91028c9eb67fdf411882989cfa403f8a9ff724c34f878

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eb0bad3f97626d86365eb6510cf6848bdc60305c72f130e8b740358ff368f5a6
MD5 f2939e005bf8d25330ea652f85439e17
BLAKE2b-256 9e8511b70d5bbee11b78089d4a6f87a375270fe1cd04595164b22619ea7ed154

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1b4d2692ebcffa94d354fd8c0a6c11fb83d55b69fec4e8e0ddbc618708e41923
MD5 a493e405099b7e7c965e0d7b557f1088
BLAKE2b-256 787fd476fc2beeaa136b489782ee439a1b9032aba81993f2f79f2d029342a338

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 abde3271fedce3ff62835e7023a6828383ed7cf20999e70e3365bf41a295ef99
MD5 a883e5a10981f92d1664faf9417046a6
BLAKE2b-256 503a87aa31ce1484d8f8568b32252e564a0dff9cd3479a3f38e91595caba8986

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6c9462b6a8661f9960649286eff865d77a42b8231921b36bce88f03546e69cb9
MD5 26148564b498f35b2c427ddfc1c7bad4
BLAKE2b-256 f1ba6fa0828676f59bc327c0cb88453add3f508e4570076a62ccce979a506595

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2dcc6ef6a6473b1f753c271938edd0744d55fb9db9ea05858d8c60fcc2178125
MD5 041e6f909b274f11d2d55d91e5dadec6
BLAKE2b-256 612297cee376315fc85a2e1d7c92f24953f2a37ddb155c19b0048a0b8b500570

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a909ebb5124a9f470dc9b8ba5fff259650dfe1b5a8ff837a6df3a54b0323834d
MD5 10746b869efea5896a0de37fc391659d
BLAKE2b-256 3453549e519dc93ec0f5423baf9ca6e2e771fafcd1764dd7a11c279fe447ddf0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1a8d0150d1017a0f08f97df4cef185fc86a142658506db995079794e994a10e0
MD5 0dc2003f0166ac9515413282f6c4a539
BLAKE2b-256 80e6d2675861c74578fecb0a8481b69530dcff7760a9b275807faaaf89c754f7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 55c785a1e20f265589708dacf3802f74369535bb84d5ae4394f26d98e196e6fb
MD5 dbb480487d7db3a121422e51953e93ec
BLAKE2b-256 53d98e511fa0512d14ca3981294023e9cc09febda4f82073715b08c645195b81

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a251f3ad74a4478ccdc7192d239d6b65e0a0d9e984499ea9c7d8bc18688aad9e
MD5 abaae68d5459bbe1a30d5f8bfa36e18a
BLAKE2b-256 823f0458605fa449940c2ad83f9fda48ef15fd81e638a5ef11c6da3bef2d0710

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f55ce2a83c831dc77eafbcf035ca377201b3ef5aabce1a4271f6c585e6079692
MD5 ab30d35ef90cf2899833cff309e7cae2
BLAKE2b-256 3ef247b8f7da6ae7851fe23af4e5fc3f139a22049437bcdc87c5c6a9edb5f300

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1f822f6197ba8c9a6a864c6550ed71c667aa06d377b9ee784824a10b49fe972d
MD5 e74ed3f1b68f4cf2e9ae5657c5d2ae94
BLAKE2b-256 98e3ce8cf46f119d723742c04e39b923cfcc80fba2637f61159137821d6ceef5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.47-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c2520e13a353723ed4ed05a319d74f03464af5047f20278ba82a1f16a599bbff
MD5 533e40903b16fbb84e33695b79527558
BLAKE2b-256 2fc1dfb89e6e1f89598e6013544dde5ae49eb57e4b8d4fc5f0de338de70583c7

See more details on using hashes here.

Provenance

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