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.23.tar.gz (70.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.23-cp313-cp313-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.23-cp313-cp313-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.23-cp313-cp313-macosx_15_0_x86_64.whl (575.4 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.23-cp313-cp313-macosx_14_0_arm64.whl (568.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.23-cp312-cp312-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.23-cp312-cp312-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.23-cp312-cp312-macosx_15_0_x86_64.whl (575.4 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.23-cp312-cp312-macosx_14_0_arm64.whl (568.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.23-cp311-cp311-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.23-cp311-cp311-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.23-cp311-cp311-macosx_15_0_x86_64.whl (575.3 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.23-cp311-cp311-macosx_14_0_arm64.whl (568.1 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.23-cp310-cp310-manylinux_2_28_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.23-cp310-cp310-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.23-cp310-cp310-macosx_15_0_x86_64.whl (575.3 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.23-cp310-cp310-macosx_14_0_arm64.whl (568.1 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.23.tar.gz
  • Upload date:
  • Size: 70.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.23.tar.gz
Algorithm Hash digest
SHA256 426e09bee76f6962bf3a9dac393e5c98605350652b7ad7a16316d51fade41527
MD5 3d5ce0bc6271880f94001b0750e63081
BLAKE2b-256 028e3255e4de3376626cc35083cd19583d14fa1914536942f8831b39675bdfe6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9e06d532c1312353c5237966e1d4e35351e431db6fe77cc7acbc866838d37b8
MD5 538f24700f6771aeb6f7ac79774f4d0e
BLAKE2b-256 96aa61306e4ef16854bcdaec799e329fb8690415e629eab3c7045c278bdafef6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b4aae44b53ae96f628ad75725c1c748ba487c3d1133b2aad3c17dd41ceef54a7
MD5 74515a10f274fc8fbcd9ca1300a8a586
BLAKE2b-256 c352ee7231516ab11797043ad9be149926ee4d2a819127235ce993dbabe063f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e4f2e75c3b0147b786b6e3689e08dd05f28b731e679d102f9b9f4ad040d67e8b
MD5 70eb495eda0b67130aa4d0330b607a1a
BLAKE2b-256 134f3c68735255f222f4223d1232411ab43bc6b2d6ea6df041d4c38fa26ea7e8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c1bdb4f5ccd8d38cf5ded1201657f3cd09bdf5dccc7d9a4cb21cb60dbd871ff8
MD5 c5e14ba88bb0ab536a68961e0016c09a
BLAKE2b-256 f067a92dc49e22ea0d27ef00f5e2dcbf024d5f2c412789457ad515c915c4f86a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d1170e1a713aebf57155d45e78ec45596a1278d4de9e0e811afbb02098030e2
MD5 f48f5ab0029b22dc360ae31bb93ca491
BLAKE2b-256 3fb17ae7903143bb47241588e066098b748a0d5787c9f50e4783bc85aa3ae9db

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 018db5d1db16f3d304ec96a3536428b5b2b0b56fc8256a74ca3772acb4d08ac6
MD5 401eef07c85ec8779d50df834b6a263b
BLAKE2b-256 5176a59d3da77ada14797ecc72d1170947e717eec8fd8d650d45aa1342ab240f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 3c1170e4f7b9b516141bebef8a4b428cd618575ee0c8127b5371c70fb295cd32
MD5 6d94528ffbf9c1c6f3cf4b88ad11a1c6
BLAKE2b-256 4db3e3719dab0a852477c7b27275702eaf78e781f96e879607303afd4dec4754

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 934ec51912c271385ad8139adec911f88ab1fe274c8d0ffe7839f2a2980b5a1e
MD5 5314f65c169b300b72515d76b2c5eb5d
BLAKE2b-256 a473c0d5ee7c3706bc9e34db27eb62c2870273ad17af4b99f05b8846f7c2af26

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4db41903979fa3a40c5740eddd1695353841ff2ee5d33607b788c200d48fa391
MD5 f5d11d444ee282215a15b7d70574e29c
BLAKE2b-256 39191907d2d20c33069c6f7e80d796aa2267268173279c8186ba2902127c6b7f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 02c5775fc80e80f2ab1c9202376b784ff0e461d887190a1c845dafa6ba5afd30
MD5 44172dff521939e864b769dab20e9ca1
BLAKE2b-256 49e8e8a1ab236bf53e5a3c1ecfc3944b3ba0d36ba9754dda5a7b0231ba8a4d5e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c325d16672432cc9204fd30be52a2c620835791da3c45789796562909bcedf41
MD5 a6fd346c732674cd10384fe5f3b447c4
BLAKE2b-256 c7541f33915c4db53a7a2c98cac748830995e3a361a6b98ccc554ede1e1e096d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 18b2b346cdb4f32e78ac3104a670b60bfaff815d772aff61c9d6599fbb1d9adf
MD5 48f7dffd2a0258d6c1d6e1f0a2007472
BLAKE2b-256 0190913150b6a3b15c845c0e2d6ea5cde6ac4b8fd63a77107d0f3233d2bba87d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b94014219b7ff55274ab7cd8685ae5d157fa53d205eb5cd31e9e1515f3ddfbd
MD5 e97a9ccd6f55265514c4128247d2412b
BLAKE2b-256 1fe0e6c8a48e128732881c887d29f2d9e793a1bf977f1d13b6af53dbc38894c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2f7ed4fa691e565888a5945821e3a4cbdc14a97831730666c474588e56f39e23
MD5 84ac072581602c84d406e5e411284dc7
BLAKE2b-256 19ee70882d8501dec1bfadf510b38485f894b2fec2c52e6f550a2ea5a40c88b1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f6cdbccfbb06f38180ded67ad44266ac4149a7054ad1238a9d04694ec68b5108
MD5 8a9340005b1f720e3b4a4ba53d27a9e2
BLAKE2b-256 19d15b0c3977558b3c55b76b236c30182ff98b1d3686e15325c18d311a283f58

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.23-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8aef6b07d74212587caca9a4cf6d58aa65d27f0a4b15870dd5c953dd479d1e13
MD5 aaf339bb2da5a1ae3319fc0e0647ae93
BLAKE2b-256 daa5f8f32769876024ffcddff6b90a3650cf7ee31248ad9f1a11c46ecaeb6e0c

See more details on using hashes here.

Provenance

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