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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.60-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.60-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.60-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.60-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.60-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.60-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.60-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.60-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.60.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.60.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.60.tar.gz
Algorithm Hash digest
SHA256 552a3ea0f21e514ff2c550cbd7ff5e1ea442251c94db278594bed2ec75c7285c
MD5 412b791631765ea51bb171a878905e0f
BLAKE2b-256 1285fd5a1e6762ebc787f83e4f4b3b5b40e61d6d46c24be2705d9b3d0506f52b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce410482d8d8b7ad9b71b49a6e74c6b07a1b089d324cb65bf16c0265ebc6366d
MD5 9c2877da340f0e556f03c6230b116551
BLAKE2b-256 70a3b3acffdf92a9f7594828cb5a00b6cd272af9a0afb464bb9df38cb5bcf8c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8d818649754a21378bf044e6b4117ec83969ff5d5e99e620be4b97b2e4689095
MD5 62250b5b48741434fd3a375c1d192ecc
BLAKE2b-256 fb90516e279033faac374421fa50cf328db7481e8fbff4d5c86ea82f44addf84

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 44b9f74462b97b235a712fde37563c76352daef541ce22f1272371ffe337bffc
MD5 a27200a455aac68d77ba3de2caca61b5
BLAKE2b-256 3d9281568d0cfcd2821c6f2ce42ed6891062a5f928bfea1e6f57a90be4bc28cb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 34ec84a9502776ad428bda985108f95c8bf44d23bfb8520c1f8809acddf5ba5e
MD5 a6d905a52648fe793a65020bd5d8c277
BLAKE2b-256 1c714155f0629f36a95186ca6a3cc6a9fe00b749bc7f340a9256174ebd54ed89

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41638e7b7b07ec93dc5465e0af157d9eb051a9caa1be1b40b72e7f98ecfff456
MD5 c146711ec9458676519ca41bdc189fec
BLAKE2b-256 d7883380a156c4312d2334ca8125517e66da1b5019b2e736a64540bec2b0b453

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3fec9a945e37e5261814e332927296670002a70cdb1e1b907048463039122272
MD5 8a8b4bc9650275cac7edf5abf7d2afb7
BLAKE2b-256 dd34fc55702d6cdc4472c60d2d4c23ca526da11ab1e3b69d60b986c256586a59

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 017812cca2e3252b0a5b1ac90d55f36cea44b5e3be687076d98b446a0bfe84e4
MD5 ead435e99f87f3403f01157a31e7d868
BLAKE2b-256 52c8c0eed7760a7fa0146623ea69458657d4105aa7775c6b38aa1d4a2f15d7ce

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 29781e141b13182ea8440244cf9b86b9ca2fc4b62e1aa354483ce06603ef8193
MD5 ff0c12f452e689728dfcfd9a2c90b9b1
BLAKE2b-256 db338ee2733037139d8db68707391dfd1af875ae339d2d93ac8c99056512e6ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ac871234ff7894ae22c3fcf523b3fe7ea28483f265fe9256088d4dbbd99bb04e
MD5 096b63504de3bfa43ca33d04930c3e84
BLAKE2b-256 393b3e7b2d8b67c85e4d5c0d7078ab0cf572b52f5f4929629f3f0ec1897a9c9b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a662d74e26257cb326892995befa2fd1fcd98eceab5f970454078e8d5852ecf1
MD5 5066fbff465b546edace773c8841d8cb
BLAKE2b-256 76bb360e5924a7ef22805af8701c92b237697b421b807b3b676f1d662c5c22ea

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4f61b5b6e068cfc519347abb03b89b53e9ecfd753defdb7921c28e1ab32e493b
MD5 07b53220291080c08105698cd446b14c
BLAKE2b-256 48b2f14279481aa2b6684d946318a8cd3764a94874d458cb2bb560868168ca26

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bf94baa11eb142083718b4dd0ec883560b088e66dd658d9acf6d81533108f280
MD5 e10694bee41986a7348706b6d18c0117
BLAKE2b-256 6b4aed4eaa379bbb0ee215de2e1e59ec6d5eda660b1e95b6a69de4ab6bc1b5c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 41c22ab6e8d638eef2a894647a0a2f6eaa1a0064453cc86c872b9af0f78fd791
MD5 9278460b8394730e4da836aea7ece939
BLAKE2b-256 443ad59407e2d9167f52be617d3fabfc9a6143a1168b798636904b0949a88765

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 93da8b91ec617639dbe0dc178115f2e9487e61c2ea35b24312901b8de7a8ea9a
MD5 57094d34097fea41a46ae6370dfb62bd
BLAKE2b-256 8eb91b2213560ff5a4ea4c0bb1544ee6ea39234efc603c828bee1a0bdac50bfc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4915adbed792ec8b85430ab7b79fd10ee9271ae0ac15ad21aeef036d1bcca356
MD5 6c6b68c68cd9b4c71099e33cbbc0d520
BLAKE2b-256 7a6dbb3efa512cb8712b0dc773f7911a6c13fa329b21f63da19708777dcc5e80

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.60-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7343941ea834c80ca2247bc47698121f6e48855543ae3cfaa3dee92159f7e201
MD5 bef962cdf5df699e4334d25ba78eede4
BLAKE2b-256 f1c86ceac2f1e336b1b7fd580ae18f550a64d322c549e2bae4596f8449209bd5

See more details on using hashes here.

Provenance

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