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.33.tar.gz (85.9 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.33-cp313-cp313-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.33-cp313-cp313-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.33-cp313-cp313-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.33-cp313-cp313-macosx_14_0_arm64.whl (646.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.33-cp312-cp312-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.33-cp312-cp312-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.33-cp312-cp312-macosx_15_0_x86_64.whl (651.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.33-cp312-cp312-macosx_14_0_arm64.whl (646.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.33-cp311-cp311-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.33-cp311-cp311-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.33-cp311-cp311-macosx_15_0_x86_64.whl (651.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.33-cp311-cp311-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.33-cp310-cp310-manylinux_2_28_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.33-cp310-cp310-manylinux_2_28_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.33-cp310-cp310-macosx_15_0_x86_64.whl (651.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.33-cp310-cp310-macosx_14_0_arm64.whl (646.4 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.33.tar.gz
  • Upload date:
  • Size: 85.9 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.33.tar.gz
Algorithm Hash digest
SHA256 dcff39c08f27ba217e66cf7921d29291299b19dc37fa5f622b2ddeb4b321f5af
MD5 d8544368e983034599ea25070ff3af55
BLAKE2b-256 4c17640fbc330f263dec60818c55be9065c66ea5b723af5228466e3dbba04684

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8c2de5fe8f15c90ff3075bb84417d7ec0e30f1bb0782e244034ca286b548ce9d
MD5 f221cb45be2acf0a7fda09cc5674b391
BLAKE2b-256 15167a68e39d3f4c680b8935f89e877f1397fe13d6210ea15a4b72cb809bb26d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ffe95982e6ac564fc0f05cc74cbc22cc401d0375b6829115d4ac733c53da45d9
MD5 0ee5e5838805148a741e00708fe0c2fb
BLAKE2b-256 91328ec1e01c5f1d7cb3d459f777d2ab25fb1e1877ce800ccecc4bbe3b673156

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 138386f672ef2a1e66fac28b99f4513b4c32c87e9184004983c18bd5687a6de6
MD5 cd2459cfb2050e2a51cf70954afe2faf
BLAKE2b-256 dc712321f144a202c5193ad03db9145ed19bb64617d92cf23c5c3f86fcae2a9c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 540499e10b4e7c04c265d56e3b6a5ffdd55a9ac1bcb5e4590f99dc0184d8280e
MD5 5e95f107ea9553467eaec80187d45cc8
BLAKE2b-256 17cda18aea45aaa2f344b8b0f2105fc44747b91c9b1967a28efd40d44c9ec67a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 63197eef237eb710192d3eeb0c554b8c0517deccf79ccc3daed97b8d04de7145
MD5 9f8fb7f61a81bcbf2d5fef874ae82f22
BLAKE2b-256 cc951d672a0c8c38d6c8f30616271049fbd1a9b7cf569956593f65b85aa4132a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a1e7500c6b45df51901361eb83e9416593601a7a8ca703f7a3f8767e0070f1f6
MD5 f899e4a46768c63025705f477021efce
BLAKE2b-256 8dd73a2e3fe9a7d0cf9d6ded62c895cb15a02c30531ef62710b59d5eba67a263

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f4a7c6882645016e206921593c59c5502b42c75cfd2cd7b41aca99222124a4fa
MD5 904b5627e30cc459ae6d5c8daad86e4d
BLAKE2b-256 b8d1772af49b5c37dfd0a051e64ee30c5e448dd91e6cdedcab4db88dda53295b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b9ac4633442af86fda1a7210983670170fd36a85f4819cc888184b18bfe2c4a5
MD5 5035ebaa7c9182c7fab7898e38bac073
BLAKE2b-256 6d3b6fe9243f510e7422a2d3cf660637466b70d2861f17c06383f129b1544c9d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b268c5e441406dff43d0fc0634bc61fd3af4ad4ff4d20b34f219de1c4e5d4db6
MD5 eb040b3d7cddf9f0597d4f4edcc179f1
BLAKE2b-256 9ac3c01f6aa698a94d92d9d3944ec3be909fe964e12ec848bfa58240bbb7fff2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d68b5491c59dd106f43701a3179dfdf64beb84c118d099b6a7a880f38e98d9f9
MD5 31a2edea588837366ec24255c16963bc
BLAKE2b-256 daec2ead174efe77973fdd0bd542f40926229833b22a1feb604aa88c584df192

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0c5d5def3c86ce792265057ceda96727eb82e106a0562120fab4dbe240e8d65d
MD5 e864cb20ef2937d570e5b9c108afd443
BLAKE2b-256 a7c1dc251e7dd067b02009deecc30d331c383922c42339c1a735e630135c84d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fff50c7ffffd48b465a0a00299bb3b30d19b52704817e65e7672e6d67c269ad8
MD5 0956b3f2db8fea894f30d012357edb8f
BLAKE2b-256 7aaaa25aeae37c91e6c62b197a4e1573ea970746227bbba51536b9d50db66eb5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7da333e5920719a3305937d437ac23b644c67b4298056166a4f1b4c2807a8330
MD5 57d90d30a731c956062f9ed1232f9a48
BLAKE2b-256 0a4d07ac7f78dfef997d382a26a976fe8c04deb16c8778eda18b7a16db99fead

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9ac6fc6cd4e304771c947123d396b4cdd4b6cf66ba73334983578760a8bffc8c
MD5 1bfcfcaf5403a4784abbe69f2da664c6
BLAKE2b-256 d3708fdf9c1b2b521652cd8a061a390271c264fd5ae0242c26bc25f03e056f3a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 b4e0374aaab83821cff342b5258fb274a9be79d6bfac0480fbf250a89cb701ff
MD5 3f7b858429a2adbc8db3bba7718ad402
BLAKE2b-256 0a54474c597c0f3c429a97a6895624e24f763b85d4384ddbd42979a03802a207

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.33-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fe52df89bd4dc9c04a6b0f5ac8751945980bfc370e57b5565dc940984e7cc6ea
MD5 e4ec4187e8f7386e26cb7548427ba3e4
BLAKE2b-256 2f7de786cecfca3deb53108822dee71412d85e3d633a0dfbe6e902662805b1a0

See more details on using hashes here.

Provenance

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