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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.65-cp313-cp313-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.65-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.65-cp312-cp312-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.65-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.65-cp311-cp311-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.65-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.65-cp310-cp310-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.65-cp310-cp310-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.65.tar.gz
  • Upload date:
  • Size: 92.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.65.tar.gz
Algorithm Hash digest
SHA256 db69056bc9ebe5cfd340c4f832f6858ea69248ff3157ebcf6cd17c1e1338fa15
MD5 0312c26fee36c68b259d319e1a1cf7ed
BLAKE2b-256 72a70c83fb3fc6e9f7d707576939b2bffdf4dccfe946d8aff3c8aaa944c994d9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9abaf094f53c143f9f7326d3fcb662f8eebecca44201eb54eab0750747bad7c4
MD5 c946edd64affe2d0d2ed3e1f9cfb4b4a
BLAKE2b-256 a0dc8ed344436a2fb573500cc9fa530f78be0fb6c76d5c8dc84c097bb5ad92a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f3b033e2bb4fb0e159dfb2a797540ca83e60259a0491004787a8443d4f9e72c9
MD5 cc774c9f0ee0f6a024db19ba7b6e0c05
BLAKE2b-256 49e2738e25bf1465a5f88262513e444f2b8c41785ca284d63f562f1363da009b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4b641c197e0d8af9d627f07bef3ffd7be2bcceee90e4bb7cfad9ad7a52af910e
MD5 6b322ebccc0dc0811dae728e1b0a3bc0
BLAKE2b-256 6e4a4ad51a3bc74eb12eae4031dfceda7162c48186c56e4bde81a1d363531b0e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e96ea427b2acc650280cee04869ff04d817216f020942dca941b478f63a7ba38
MD5 7413ed5ae308d60b82ca06334dc5f996
BLAKE2b-256 41359f1d607800ef959d3b896b5ae2bd33e9c1677baab71b499f0e92d8bbbdf0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eae6dc24bb1e715f9257d0ee3b0bb17d28debda760870d3e2a70f81a22e72c24
MD5 b21e29d8cff754d25ef5ca04f62b946c
BLAKE2b-256 0ef692e91a66f79350d9815ad8c147c7f7b546dbe7ae6120b8ffaacfe89d7788

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fd37e39d4b64c94c20da24ee4c912409ed38cb190cf666186c9b1da4d4bcc25f
MD5 aeb48817c390cc90f59c932892f10142
BLAKE2b-256 b23fdb59ceb34bedda8d73ab88f8320164b8e9593d6ed70d410c3e528fbeff6a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 04bec35fbf61ca8c40daaf40cb5c5d3b7cd4cfc99d987660ab87a15ea5da5df5
MD5 b603b5ab089fdd62ef86ff7a803dc687
BLAKE2b-256 1bd78ac4cc3d4ad813b650f3364278cc6fcce0857f1cd68783bff668bf6fdbeb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5cc32eb60460b29d4f488103508bc3dee9c183e960edb6ffeb3aa97e430419e0
MD5 cfe29c64d3b6236d281445461ea7fec5
BLAKE2b-256 c0ed534ee52471e56578c5e3931ef3fe1a416f54c223b933fc1aef2e2873b0af

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 359f9bbc0e25c702b7fb2d203eb2f41673bee0ae4987f981c333b7af66a14dbf
MD5 bec37be88d07787134cf1e86d0645ee9
BLAKE2b-256 21151cc1dc2a9ec0aeecd22ee02437747cb89c51851b6548006852b8576b5d7d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 640c69a69b2125e055efec53c5aeb11876b102e3d738d987d2a2063a69f61406
MD5 1e8269998a722c2088a385ebaa8b213d
BLAKE2b-256 40c6dfa30fc99953b1dc519e3bbe3bc6275a04770cd46a03af100a181862a581

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 43a19b4a2ceee9bfca83d15ed745f4a1d09d001acd391c4e2e6fbc19717bcdb2
MD5 3d3f8afbf406eb302aa0aff546c2b91e
BLAKE2b-256 8f2dfe7648ca5011a9b55dd58841f86ea59ec6b24c2bcc8dffedb125fe9a4550

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 69ab662b1b83eea4048f7c71a5a35fb330160c8a28e2c1e28d402d2977baf1ca
MD5 e4ae833c33dc575493643640d49a322f
BLAKE2b-256 e568f234cf6c83d036b53f09890d2c5ef93d03704c1fc822564a5b565e296c20

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fe796f2d414e12bb8556906814f0a4e54c95d18dd35b04cfeb68b6c694e9557a
MD5 930cce1743ec2ceb92b23b3ffd2ac8ba
BLAKE2b-256 af9ee853df272c658bb23f01f767f9c0630b37f8bdabe81d993edf5f2a4538b0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7d13bf0f44b3229eb5c0bc968e3855462e1ac2b07b9b34bb03bd5e19927d3fc8
MD5 850e5e9bfff3c6e524aac2426b4f23dc
BLAKE2b-256 31278d2be4a20e5b0fab0f824d3ed3a12dd172edaa4a548dd6aa335671df0b1b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 00b9fccc62b9bd65f30eea1f1ec83499e72a87fd1b517f443775403e059ea747
MD5 b02440d969a186459fccd1ecb6725600
BLAKE2b-256 d1f54c34fe931eac431a7a89e91de0e3feedd592866b4bb4062fdcb0ef7e61ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.65-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9144e8abdd3bf4e2f5ef338bc21c5fffbbe4a0ca589b4c6cb0344b5bdef83970
MD5 71e89cfb8a95b228be2e5710ccb45710
BLAKE2b-256 cefbf946fc72c3a1e4870b07a0667490d1cc0aceb1c833b106ffa6cca3eac54a

See more details on using hashes here.

Provenance

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