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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.24-cp313-cp313-macosx_15_0_x86_64.whl (575.8 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.24-cp313-cp313-macosx_14_0_arm64.whl (568.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.24-cp312-cp312-macosx_15_0_x86_64.whl (575.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.24-cp312-cp312-macosx_14_0_arm64.whl (568.4 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.24-cp311-cp311-macosx_15_0_x86_64.whl (575.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.24-cp311-cp311-macosx_14_0_arm64.whl (568.3 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.24-cp310-cp310-macosx_15_0_x86_64.whl (575.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.24-cp310-cp310-macosx_14_0_arm64.whl (568.3 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.24.tar.gz
  • Upload date:
  • Size: 70.4 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.24.tar.gz
Algorithm Hash digest
SHA256 bc43aeffc2dcc26a46b5e0e770f218b443514b52d32a6114931c06790738a7c3
MD5 630b1bee50eaafd69731bf279663b8d7
BLAKE2b-256 54a5d00779f9c6780864062d93a37b79b844af248cb58de84801b35470a80acc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a4110b5f1a5a39b4dc68601b2220a493ebf1d97168742c7660144ebf81c70913
MD5 3da918f9a3e845deae39eb40a2423c8b
BLAKE2b-256 fd7a1206ff6c29c96708768bf57c6805c2abcd8317eac5e1c04ed73c52d076f8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 66b6eb1a01a69d7dd29dbb5b27f42b976d2dce68f261bb6b38a00c8337aa7ad5
MD5 cf19f17357d523f31d808f17319d8e12
BLAKE2b-256 4bd9f72882931da12802fe15cbb5a5da9afdd239f6823cb3ffaf22795388f33c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e6d6420716266fad73a188ac9e945b8c3b8a34308caf21836a436a67b1c19710
MD5 14a06b6934b194c6395abcc2a2c22c7a
BLAKE2b-256 789fec2e577d707a72191ee58d4ebacafdb3933aac01d38c7c06c2ce946e6ced

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 fa735c29f1fe065151ff678084e0350c695b2700c00f62e67f42f7ec5dc88298
MD5 f006a0f0aa41d1aaa32e631251d089c8
BLAKE2b-256 a9a34cef4440f1dd6fdcfe43338a3381018c5cfd167c146af9bbae091b19883b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a2d8dc2fd744ce6bf1b6a8694901a1f83b6946c56555e66b0b79db615dbd174e
MD5 c230e08d7a651c496126b1d452d84bc5
BLAKE2b-256 26e2ad9b44d5e95bc4d817f9a53b9798e69c6a90268725091bcd4082354628be

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 9ec8bed1b2c1967fcd23343636385b4c849982e4c052efdc5f579f9706784706
MD5 1141b713526d5e2c88a7ab3bfccd37e7
BLAKE2b-256 747af95df3b738210967468a4d259abd0827047f67c8138565f9e9c53111b89d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ecaa18bbb62a50df7807982229da9c7aa2335e3466f43cfa02a2ba954403b970
MD5 2850eb7a051146e5075c79c7c7c46db8
BLAKE2b-256 a548f5c9577331b95bf368687cca360b09a48aaee749bf48f0211d522dce7fca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 daf40103c5c5cb4c3ec0e9e182729e30047e60a2f59b7cc986a4d7eeea1a0df2
MD5 48947756cac1191a70f578fcdc3bf4c6
BLAKE2b-256 4f3f2d0eb1bd7e2505563be406449f530f1946362f43e1605807cb0fe1068ea1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52bac80f1939b361fb7fd4350c4daaa803d2fea6ab2bd622c313e4ef733b785c
MD5 3d87877fdc0d53cf6246a6f5c747cb5a
BLAKE2b-256 0f788a60e3ff2b97e3ab63067f18f7dd486990375d636c9202fe7ad7ef2285ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c3e527792282022d0231e5ec017037701492af1fd181746079889c4a4a3c853f
MD5 8f97bb2c688b98e7b1117dec361c684b
BLAKE2b-256 3e8a83068b80946733edf7ce69d35f8e8b8ee802d9f026deeac7ac8a01f1f49c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 762a8e13e115f2b3bddd1c6cfbe230b336aa2c61c79395269ae1ee85f937bbb5
MD5 aba0b2f050eaa3bd4b1872605389cbe7
BLAKE2b-256 69f46290939fde9d0f69d05ed0581fbd53034051fbd515b99c964313909adb6a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8a350620897392f0454d0f8e9f4a45f0aa49928abadb7af3b866041d84d46752
MD5 61d5e3af09f0163483427af36985d427
BLAKE2b-256 4810cd301ad9bc734c1cd69b137dcc4cbb71a033b8b464ed03f16024f8a1d779

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2cafc6fe0ffcf3a87a880d8c61b60ba756af27e5bd347efef079dec882c5b39a
MD5 52d134195fe425e3cb89360d96dbdff0
BLAKE2b-256 d86bcc9f7971774298ff178ceec861856cc4bbbd2d45955c8b2177c41af60b0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6fe199780dd36b90773b1e6ffb45be482f7ee551e3a34412c46873137ada8860
MD5 c369cc86c64625e4b5afce8b398c6fe3
BLAKE2b-256 e74b2f16e899cbcfdc9b7fff1fe582fb15e902a768704f9e05afa278716af225

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 efe85c6e6f8aee814b5ac351985ed54dcf97c3f05ccd99e01b2b2b1a432cd209
MD5 21f55b7e8c5f3ae52fa98baf36a64e70
BLAKE2b-256 53d76a2281fe98ba1e71b774b3870a1c9e3d9047619f9b808c6f522fb93ffc3d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.24-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1bc438970fc67428ef849d2a449a52ed38ea270594690548555dbdea8d8d8ab4
MD5 67e6882b0766583caa3f7224d59d4984
BLAKE2b-256 f8afe940182d3100784de46382b93302024028290c39fdb75b7b75a8dc126a27

See more details on using hashes here.

Provenance

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