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.28.tar.gz (71.6 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.28-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.28-cp313-cp313-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.28-cp313-cp313-macosx_15_0_x86_64.whl (581.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.28-cp313-cp313-macosx_14_0_arm64.whl (573.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.28-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.28-cp312-cp312-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.28-cp312-cp312-macosx_15_0_x86_64.whl (581.9 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.28-cp312-cp312-macosx_14_0_arm64.whl (573.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.28-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.28-cp311-cp311-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.28-cp311-cp311-macosx_15_0_x86_64.whl (581.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.28-cp311-cp311-macosx_14_0_arm64.whl (573.7 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.28-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.28-cp310-cp310-manylinux_2_28_aarch64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.28-cp310-cp310-macosx_15_0_x86_64.whl (581.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.28-cp310-cp310-macosx_14_0_arm64.whl (573.7 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.28.tar.gz
  • Upload date:
  • Size: 71.6 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.28.tar.gz
Algorithm Hash digest
SHA256 322133ba3e7b412cda61c5504aff7a8d262c4f585b160e0a9d8af513bccd0fa9
MD5 77a59699a637a76851e9af8230b3e60a
BLAKE2b-256 9e7bf5511b2a6300bd3a34b40fcb930f3af8719383e45571d7f09ba20d4d3803

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aa55d0332ab8b2cee14d8999fd0c0c537e2d3ae5e851076499cb1316e92d185a
MD5 a1fae9485f62496d97615eb3898cc9d7
BLAKE2b-256 ecf0de57234833901390982ae10ea3841901ca666d265e87b37248e6979ab070

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c271fc7d0b017b248a7a1cf7b4c8006bbc09fec10c0e5650d99226049671524c
MD5 2b24efaf9fa1683be6bd4a7405601a16
BLAKE2b-256 8af5f2ee3a8cef87626597321a809bac58077e261202be34f285e1e38aef4067

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 333b34fcf031b47e278b44ee2e6667dfc2ef748418f0fa6d435098e39f2f8e6b
MD5 ebb0575b68eaefc962225aa2fded0890
BLAKE2b-256 d93638d1768fd42d99a7589d39ab64b9eb7021df8cb608c714a8d0cf98aec91a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 3cca05085319a1782f893c742f733f8edbb4854a484908f766cd7164fff9698c
MD5 df8cae2237daff35eea07d90f85dbe68
BLAKE2b-256 ae271f953d2b8957f9ca387e7e738c99011a56e0a2262ee3ba0429c4cf3dc4d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 320cd332ea3cb1f7e20d2cbd4e26865a1425a7c57bad394947a207dbd5439b5f
MD5 2097fa6fd09b21a9008406070c500e4e
BLAKE2b-256 92301fdc1df41fcdb790e9f6ff62616c17c85faed7732f31682f43f03b8a952a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 df723a538aeaed83b401dd94f887711825be8769de4c851e8a76397cc8413639
MD5 10e2e6d687bb28e3808ca72d6a9e6bd3
BLAKE2b-256 8f22ee312e8f1ed86ac56c34396a0003eba2086164d9c2bc3889f19f383e9d1e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 a2bca43dd94afa57cf14dfe24ed48dd6d24d7a7cea06d16381a889c7d216b335
MD5 b5039ff1671635a4c9852bb30b7716f2
BLAKE2b-256 abcf5eb2b7f052bf97422b667614c9a1025d68cf1f39ae5fd4c1c73300516922

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 874834ada770ae4b45d363c757fba3d4b46daf282011486c242992644fd756e0
MD5 fba7d3d9982565f91a39588616364081
BLAKE2b-256 fe4d577a93a991df7634530ba3212692d4cd1b2f8126db7dc2dcc15a5aa3a7f3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df6b81bdc942016d9ac2b97aa7f2304092d180c79897df33bfbcff96c619c702
MD5 d40c38242a3135b0e73bf8756faf2cac
BLAKE2b-256 a0593b06e6c1c351ab62276f5410200787a551648727448bf2c96c37914f6721

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1d64a44dd2077ae3a80a04e35cf072133503713b6be0a841849c7246f2460693
MD5 970b02104e1a91276674e0b08f40cd62
BLAKE2b-256 78fa810c23bf20945f5fece5ebba6f2f1b6255b7f1b44941dd82619894cf0a20

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0ae00aa3c2ec100f3ab09fd79b824f0ccfb23d8ca2f47db84d4b8f1a44bc0948
MD5 a2dc2b8416a1d982f806c1cd1db9c514
BLAKE2b-256 34c350c21b95591aba9d3267d9ae7591133147279ec97d3773e39e59a6ea1ae9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0e4a80f1a5e89f3abd72ed61d63a43a921d56d404c7657723d4815cd51ce8c7e
MD5 ba380dda895f040a613ad0e0877a52ea
BLAKE2b-256 e28ce2a67e86501be5032ceeb588411a60106d5ccbbf4abc6615d845d5c99ae5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6f6a9703ec5aed8e8196af2b2ba5fe85c58de47e15d2e18fe709a029f619b17f
MD5 4281b270ed2c4b946a641209aa35d7a4
BLAKE2b-256 2bcc1f80ca4fefedd55c8f940a25acde98a1f51a6204a12e7a435262d855f60b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 17187e95c5220a59face176fe392399f08cde8f265cdc938662197345b91d223
MD5 9d483b928a023945bba7d58d0f02f701
BLAKE2b-256 cfe2efec4fcd3d9ae7317de4469d67ebade33bb6a81886ee2215c4aa07d18d63

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8f07de4633b8452698c54a874004092e8cd9ed054f5f6fc91fb8b3ad6d675342
MD5 3a755f8495a5d0606f27a3dc33d627a4
BLAKE2b-256 846a6ff42150dbecc712c2a3b47697da55efcbc4892fc0728224c30491fa7284

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.28-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1e082cb2f92843ef9a8bb395c096a0c576ac10053aff6920c7466db41d154313
MD5 c9ad2fdff4b42fa3e0ac91bb122034d1
BLAKE2b-256 8566319b701a114c523ea0385925d86c5b6ce2f91898b509e0671df5d6c77e10

See more details on using hashes here.

Provenance

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