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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.73-cp313-cp313-macosx_15_0_x86_64.whl (666.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.73-cp313-cp313-macosx_14_0_arm64.whl (656.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.73-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.73-cp312-cp312-macosx_14_0_arm64.whl (656.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.73-cp311-cp311-macosx_15_0_x86_64.whl (666.3 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.73-cp311-cp311-macosx_14_0_arm64.whl (656.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.73-cp310-cp310-macosx_15_0_x86_64.whl (666.3 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.73-cp310-cp310-macosx_14_0_arm64.whl (656.8 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.73.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.73.tar.gz
Algorithm Hash digest
SHA256 0786f87b9f3e26264e97cb934817d4362f5e061e6a380fce46ad1d5b26239eb0
MD5 f648df877e759bf6a4563b6144f34b9d
BLAKE2b-256 c11dad491076281b06e16bf38c9c6fa9783b7aad27e2ee15a92a048522eb07c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b1bf240b543332eaeb5a8b974c68cc3e2226276951ee7856aa8eaa1cb4dc2147
MD5 e779f807181ba039a5e076fc50620be0
BLAKE2b-256 7a1704417cb9ec322551baa6db9ea0103bd7af0edc71b93506f6a1ae0401823d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 416a057a88d7d1dff77eb20872d8058c2b65056393d758885b3ee479676f34cb
MD5 2fa6263006089aecdf458ee58ac99d76
BLAKE2b-256 0b57c8fc275546f0d74e0ada98d8002c4eb18758677b58fe182f8327d70f56e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7eb9b291615eb23e08383fc6c4600a2bf3e4a9580396956531953e1ed7a309a2
MD5 81afdec5fd06352be69e2e17cad43c56
BLAKE2b-256 c13d546b4b8bd62ac4c5f7f6a652805d16a4199d6013d9e4c9537f05a81884c5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9d84c1b80707c1b448923830c46667268805534b958c5f3907cc8ba55b2b8025
MD5 c0364b0359817574cce66fd942d78470
BLAKE2b-256 ad5559401f6e6693fbdd04b92a34812b09963b8b786adf27df87a820f236b06f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 05d221f5191187df89bfcb4b2fc493334d5084c3366d3cae6d2fba655a67f0a2
MD5 6cc28ffae04b93acd534d380e5b44821
BLAKE2b-256 725016f645b5c4490e46e4b93ec77c65c518e1f317f359509f56ae08dfce45f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6f7ff11f0fef28eb501db6d582ecd23b7e40338556030c7e5d272bc9da9b6789
MD5 47a1f0d86b8b529d7e0275a610d01ecd
BLAKE2b-256 b0d4162a76a1b4509a71bd6ea29979010f2aa510b0a2a71dfc82fd2223b0c5f2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0f592ab28a086748904028ea726111ca18e17c5f60a034749cf4bf640fe94bb7
MD5 aa093ad31b1738a3e54ec7facd16d5a2
BLAKE2b-256 1e15df4245e08b5fcef6e1047a779aeaf0c01b55aebea74e35c495ec4e30f347

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f799f8a85da5e4c9e50fc30122d5521e86ef02d64438ae2e67e05412c18194cb
MD5 405c030115c4a6fc6ed2316ecec3551c
BLAKE2b-256 927b6330f02a0fd0ee6951aeb23897fd4a04839cbb2ab9ec0c7f070cd787ea36

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e0bdeeae5be19751cb10d3e43c06bc1b44ca3e2dd42a562954cf2becd4c6b41a
MD5 536766ea2ebe773064d6caf58aae0815
BLAKE2b-256 063f3a57080d01b43ebfd0889d7fe766ea6ac3b276d0dbf7d771055f9fcf7092

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f53a358a746166f759cc2ab1804be2c3cdbaf4df9f96cd49a6f08e1093c48343
MD5 e30e40733e236374f5d8bcd4f11e25bb
BLAKE2b-256 5b7399ad783825697c17f86bad5de361ba88ccba737b66f44a3fc2842b30b83e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 489be3b8ada25da50066fa232abbadefa893875740084ed9c702bc9dd7aaee6f
MD5 5db232d5a18ab2d47a36456a79298c69
BLAKE2b-256 fc37c54cc215f3fd694a7ddbc8ce483b39be913d18f01a02dbb011fd4c41c374

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8038b107a4f335e67cef028fa6a758a1b5d88e89071823e1f624e5b03f2a7e4e
MD5 7647c7931524ab5fb10dccdf2df9a1e6
BLAKE2b-256 66fd9b1bdba8d0611455ea894d4b6eb75afcaa93337c0d7c2a8b19514c46e8c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 62a5cd2453656ca77f9ba0a13977315ff264ebfebe80569ad1dff001771b7da0
MD5 06ffa39bd34f6bcacec9138dfcbd914c
BLAKE2b-256 a1ac28b84b3f285653572b651b05b730e7fab39b768f51fa684f2bfa4f498978

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 987a71cccd65c264013172498205c0771172a2d4646ba8a9f5ce544dacf1f7a1
MD5 cff81457fef6497e1a0a045a4f6313b4
BLAKE2b-256 31b3af2b569d18aa1f9321ede832ffe78d9fcf46b83e1abd967d09397f184605

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7856350e4eddf58443ba00c23995bf3618c67be5c92c50a10043ca1885e317ba
MD5 e0d60b99697b12f44e0755437ee14ce6
BLAKE2b-256 f2c69275d6be58a381d283eec49cf21da8d78f4f555f8a53acb203cebc6cd655

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.73-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0bafa04a11eadc9783d8b235c24f59a5317494bee2e3a4d63fa265587da89189
MD5 a0fffbfeccd8ea246854bb23e9cd9dc2
BLAKE2b-256 5f78edc803afa0bdb7f9007b8301ce3c9ccd19a8e90e5af1270412ad42f85f6f

See more details on using hashes here.

Provenance

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