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.42.tar.gz (90.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.42-cp313-cp313-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.42-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.42-cp313-cp313-macosx_15_0_x86_64.whl (663.0 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.42-cp313-cp313-macosx_14_0_arm64.whl (660.6 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.42-cp312-cp312-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.42-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.42-cp312-cp312-macosx_15_0_x86_64.whl (663.0 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.42-cp312-cp312-macosx_14_0_arm64.whl (660.6 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.42-cp311-cp311-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.42-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.42-cp311-cp311-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.42-cp311-cp311-macosx_14_0_arm64.whl (660.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.42-cp310-cp310-manylinux_2_28_x86_64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.42-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.42-cp310-cp310-macosx_15_0_x86_64.whl (662.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.42-cp310-cp310-macosx_14_0_arm64.whl (660.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.42.tar.gz
  • Upload date:
  • Size: 90.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.42.tar.gz
Algorithm Hash digest
SHA256 2c6fe93c7c031280543d0a335fadaee0d7a0eba644f41730d2d01a8fd92c449c
MD5 7103e07ea2c59c212d174a7e9ffc5252
BLAKE2b-256 906c6e18630a7c9f6f3bfff766a4f8937f8a26c3ac5a13e54f5988f71af41ce8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1b8cc559289232aa1636ff8a162ad1d1ea9fb20a7c23ca2ed4188188d53bb4af
MD5 dba433e065b7329027931b19c2920eaa
BLAKE2b-256 e78bd55e97dd0f31b4cc5f4fa61cdf836e9ca7dd0091f5914c1ca50769831b2c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 bc8e817cb19750f1fe9e5c13732965996ceeca24de0fbe764b58e7c5d8113777
MD5 3044b08573c389a18e3cdbbc65a58cd6
BLAKE2b-256 680d70ee2a3719f96783147aac554bfaccf130677913b59f2b782b764656c49f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 748232ba9d608cb9f8517695f25e5e6a385f012de70cde8ddddc13285896004e
MD5 adb018704466444e0a787f395791247d
BLAKE2b-256 f074a2a0fabca94e8bbbc5a523364285d264cbb58485e44631458e4eeaa69fa3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a762c01a52af36cba8377ea5e0e642e795b29d82ad8d457564dc54cc2dc19343
MD5 4dedd0aba76becb23556199d41b0b45e
BLAKE2b-256 2c2a924a585996f38c5c68ad2bfe5d7457b0712d109daa1c72c98976ef8cd854

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 baed6947807f511187dd5348601de9a1a41546e23d3f96d0d4442bb9a2b90205
MD5 08c6cfe1f074ae61590c6e552deb856e
BLAKE2b-256 e7bcb49755af022235318fed3e3a0a71a4b112e104f59d4a0338dac6e14df61f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 de15156746ba9e606ec40f1bf4c6a7d4e884c0fec712b9f18b4aa5fc950ed181
MD5 5e0fa7cbc8e982ff5d3c42ca968b7d30
BLAKE2b-256 6704555407716578257493e1d73e9170d1cf6e0de153ad331e25ebbab9e3eec9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 790d6c74589309ab22136425829dc7a8a69f1e62fdf6de1921865647757478ae
MD5 c3b27b855fb5458140712431ff2dcb24
BLAKE2b-256 cd4cdb29f5758988cac5dd05499f9a736e753a03f2fa505bf7706ce171aec74e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 745807b424fadc90ef9702420b024967d320e461739eec136b6f30640b481928
MD5 ba7b1bd73faf6cd8263f533c458965d2
BLAKE2b-256 4924f5b5e7427e8648be1aa8a8bd81c09ca4a6cf91cad0a816e7fca13a08941c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ca786f625ac4c22edf0779eb618ad67349d02e8fcc4086c94a7761848e6e1e8
MD5 e58c49f3b8a4d494ed0a586aaec76448
BLAKE2b-256 c634883af85d7ab130e1a0f9ad74517fe28427b249459ca01d6609a38ca7cf3b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2751035410b99444815db7f36668eeaabf30dd3e1bff49ee80e4324db330b9be
MD5 e5dcc235fbbb45d890788259c28ad7cb
BLAKE2b-256 192d1ca1578f0f4baee91a051b296499952e1a192114fed6a859b77e76ca81e0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7c6202344e9218b96fb8898ce70bf2ba9c35f6dfbef9901f8699cf0cb9ccef45
MD5 ba447f6a538aca940abb6e0c83abb442
BLAKE2b-256 527da17be2b832f6d2d46522f5d41f00f373d08202ce424bcc9a8a57cd38610d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 bc05209f01de201cafa19b854b42f0e82bc5e90ea0b8853a40c6e1ed5be77045
MD5 c1b079f79bd872f6ec142b5a9d2b4923
BLAKE2b-256 f8a281d520359d149fcb2e0aa26e93642678a286f683df3cec58e4435d5e8bf2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b754ab68a7bc65c47f94859d9dbc038a23bc1d24e49b6aa27b6792c9c734a3e4
MD5 e48d4cdf97e49c4a3351015f1f0e5733
BLAKE2b-256 f524c88daaf1aeae97646e7a9984614695eae756ccf2c5d628a84b82a4fff1fb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8e73e7e3f99294b99ab60ca701022f9736c70980e2547b5bf777c68be1702e98
MD5 4fe128ce208fa791f0917a4ba0b01f48
BLAKE2b-256 7f158408dc889a3ce94c856bd54d9f63e7e11cb614aefbb8e65b4fc8cf3da810

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f2a4a96046007901240a38955982656f42cb8036bb10f58f416b20f6c48099fb
MD5 8342c2f7d5e8370a7357032d25c6db7c
BLAKE2b-256 c29776d948ef103397fe8decbb5be83d25e072bed1adebb16b22c3127273a9c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.42-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6807cac82edceb7f8c0eaa1d3320fcba786190854622c81e4c770d66995eefae
MD5 f269181183e434437eb8b2d949200013
BLAKE2b-256 24cc873460a3b2be4139ab57c7959cf146cc84a7f2f731209e8e598727383149

See more details on using hashes here.

Provenance

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