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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.69-cp313-cp313-macosx_15_0_x86_64.whl (670.3 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.69-cp313-cp313-macosx_14_0_arm64.whl (654.3 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.69-cp312-cp312-macosx_15_0_x86_64.whl (670.3 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.69-cp312-cp312-macosx_14_0_arm64.whl (654.3 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.69-cp311-cp311-macosx_15_0_x86_64.whl (670.0 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.69-cp311-cp311-macosx_14_0_arm64.whl (654.2 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.69-cp310-cp310-macosx_15_0_x86_64.whl (670.0 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.69-cp310-cp310-macosx_14_0_arm64.whl (654.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.69.tar.gz
  • Upload date:
  • Size: 92.0 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.69.tar.gz
Algorithm Hash digest
SHA256 583fba9ba1125348e4b748b1d86e89ced83dc966de5f08d24041db421e8691a5
MD5 ca8a797c0b9302ff346dd509a2079968
BLAKE2b-256 891eb3cf018b08692b494dc13deb7ddaf780a97077929d24012f50a7148da1e8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 48bc43caa23c09233cca2d2e8815ba7926b505b67e849e4aaaaa23a4062bbe99
MD5 949de461904955912d1acb68ac35b39b
BLAKE2b-256 2125a95293d3a33e15bc880f98ab99986c42aad3d0a173b33f4125b37bf35425

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e68c7186983b98bc5e215e87579db622cdc2a1717cb28a01d32a25c210fdf8f6
MD5 8492e9fc4155552279573298e7a27ba6
BLAKE2b-256 16e2d4b41939fe54a259da84bf67fc871c1a3005101c0ef4e7e9266ff2e3c851

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 44ffcc5f673d3fa21e5a7d83fc6a48bcf0116253aacc9dfc73a3648229fc63d8
MD5 724a1ca0d2c0dcbb9c00f47771bbb04d
BLAKE2b-256 9fdbbb55e0e2f0417e3243b1d81dd33b4d39b57c5d43b0511189138ff9b92ec7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 27bb2d59d86c982975e873a2863c0e9eec611a99b4212b0cffce11eef6e0b950
MD5 b2d5f51c0531b856049b7846254a2cd1
BLAKE2b-256 9d204201a6f006e213373cf189eed111eadecf551d4325699bb3f3f081d520e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fcf8b40f6b99f0257f4881340b40c87ab56bbfc8414fea3650668ef56982ce10
MD5 76c5c2b155b6f510996b1b5f3579acac
BLAKE2b-256 2d233238479d7acbb65cd7bb2bf395c0ab552c5e15e307f677d4f8808dc366a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 40469d197c98a544f58be4cc93402aef94158481fd39887fd6531086483cf059
MD5 fc38ef56b1a3be73afac0dcb15b85fca
BLAKE2b-256 aa128a912011b7177cf2e9b105638c1b644dc0a6545c4843885f2818f9af39d6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 227bb3f15d8beea1d6a63b5bc8f3ac17b01067b3100e69ef1bd71ab0e67d0b22
MD5 f1fc93b903e5e259c40752d2609d7652
BLAKE2b-256 dd9013fc7d638648ce902aa43f9e925b4dc030d29e662efceec95194a272be50

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b51457f85b2c6fb2d5b7d4752f8c34d9456af9abb97cc1c8aadb001f990359df
MD5 b4042f0658dccb050d3d83f6b65bf077
BLAKE2b-256 d22443a1827990c3f0572359401db0aadad1621379f18ff90ca1247d2d2e45e2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d503ead8e0600a952e90cedc17cb9388e2c4e0575318e1690f4f38d5dbf1a46
MD5 abfdd659ed2ef79c0fb97b1176681ab9
BLAKE2b-256 e15135f46e2b0ff7f7924c68dc7b8a63604fbb029007998cf8907f8236ae4f60

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5414a0340a1af247665ade15c517a9e98833522d74d48046c580cf6f1f7dff2c
MD5 d81900fc493715f21c5781471e408c35
BLAKE2b-256 bed8b0206bf7025f2e323560a9af2204e65d1171fbb32e5c5580dab018e7469c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 66b90d01854ad1c0744858424339563fea7e8b1071514f2d7aeb23ddaec6c6d9
MD5 c338bc08f6ac223afbbfcf26927410a6
BLAKE2b-256 e1b9c8bcdbebd973a6eaaafe92936fed2dc144f213d99e336657f701b34776a7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b8e41bcf3fa3de567ac0e0127ddf344b5a88374ae57f49b3b458d6065d2499ea
MD5 467a8b7ed1c118e3d97dbe7551c35311
BLAKE2b-256 49f9d8ec2a4c57f044cff389eb2b524feaee9d5a2a30287e2bdf5a2848febb14

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3475d0b62986522f29f92dcf2db0e5458a25fa00701b2c3e24b449d907411760
MD5 1a7ec4b0b654dc18127170d6503cd468
BLAKE2b-256 630a744cabcf488c93747fd091c7221dbba856c4a97887f868e6c0ef48fd7ef3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9ace5d71248b4259bbb54178510396b4414904b1d5f33722e82d11799db2b4ea
MD5 7015d7448ed59cc080b24a022f7da24b
BLAKE2b-256 67d8bf6918c7bac21643758649e7d305179e7560dd441f65f498f837d385c118

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 74d91d1e836c82f3fe1699cc39d80391e4760b620135968c2ccb2f47922ae6cc
MD5 fe3960d07575af18a86e1e5a6818051e
BLAKE2b-256 32cc4f5469a91a1114c35b51e161622a5bd48872296c821c1f5756a04f445919

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.69-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7c17710884d1b61df29cce920c136c5007479a57c8c7715b6b10a6897853665c
MD5 8ca31c1ac750c9e26ea4566cb2075f80
BLAKE2b-256 3134f22e1016858af33b1cad209ec88ad33e262bb83a5fd813985c473feabad7

See more details on using hashes here.

Provenance

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