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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.43-cp313-cp313-macosx_15_0_x86_64.whl (663.1 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.43-cp313-cp313-macosx_14_0_arm64.whl (660.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.43-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.43-cp312-cp312-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.43-cp312-cp312-macosx_15_0_x86_64.whl (663.1 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.43-cp312-cp312-macosx_14_0_arm64.whl (660.8 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.43-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.43-cp311-cp311-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.43-cp311-cp311-macosx_15_0_x86_64.whl (662.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.43-cp311-cp311-macosx_14_0_arm64.whl (660.8 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.43-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.43-cp310-cp310-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.43-cp310-cp310-macosx_15_0_x86_64.whl (662.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.43-cp310-cp310-macosx_14_0_arm64.whl (660.8 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.43.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.43.tar.gz
Algorithm Hash digest
SHA256 3737030339f760f10a18f50b0964be7bfaff5d3f65494dc7383db7732726a802
MD5 897e1d207f549fa662c42966ae636edc
BLAKE2b-256 772d9e5b081c97bab116560291b2616595ffdb61b1452b342053b3ecbc9490ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 577f51f9468305d7aa57ccf822f98a88010c7977ea1b36a36f01b47a0e0bd8bb
MD5 49521df37c0d31f9a35435a9b91e4270
BLAKE2b-256 11d6eed44d30221b4aed11d50b3af7e8690ceb35c20aa80004311942f12ee035

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 730e3229a7f6c8289a11fe406194fa7535f92935a8632bb7db12de2f8c876fc9
MD5 15d7a5886016baecae4159d83e6aadf4
BLAKE2b-256 fd3757ba3ddf4eafc00d0a684a0303a92451551f1251efc70d668d18c6960010

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ef1824e0ad301cc4f4ddecc3c7d532256b6d523bd5189bc36d4ed75e7f6d52c7
MD5 90608556a17001d8806dd6c03f4f3f25
BLAKE2b-256 3177f2acfc6b6621f0896ba99b203ee2a89cd8c7098b199b4b52680a8d67ace9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 854c2e9295b7b9f8bddfc2022d0694f41159f11aec0ad50a259f6e332859174d
MD5 978ada3dfd98879fb1b3c0adf3308af9
BLAKE2b-256 0c180651f3b576768b059ab17807ee18b4de358617ec4c1eec0fa060a7a3eb8f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9f60fe933f206a181ef27d73a06ef8e80f36b3222409c430d4683e4dd1fcb800
MD5 2c95975014925fd86c6134b08d44498d
BLAKE2b-256 e4f997b344f53f7166b170aee1295b72d7ab09db4c961cb99c4d63e5d806deb3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f6827fd432cdac79a78e7004d2c8d42ef3a6bb83fe61abdb54ed4db71eb88b88
MD5 d890a6fbeabc4f913bb4e82db58d2994
BLAKE2b-256 191658c66bfcf7f8f28d43506dabed5137b517ba14151b190d5a782dbb67b176

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 814c2f986d10a90ff524f26cfb7d00d4847c1ba5f0056c72da552a1ce65f9949
MD5 d76cd19067010c9db2632b506240081c
BLAKE2b-256 23587386d1ead0ccdbe7af55a39e5f4182fbac6169da07e167fbc5af3ccb1342

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2435d6f8b4f61ef77bf9da6d69c66a3e1b2ebed9dcb854e4d702b1232cf100f9
MD5 b54aa844b037abd9c275dc4c09325a12
BLAKE2b-256 30c928d9678091f9fa281883f302429d832079f4e538bdd1ba5c3d33ed1e6ff1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1268a2132b860616a3ffa324fb5c5c519dad326549502b972749634c4fe693f
MD5 4f3e53f19a46786e143ad796d613cfa9
BLAKE2b-256 32fe49d67ef6cecae91ef19731f46ac84a4e1067ee30bb162df42914166469a4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8cc34dacaf0a83a7933ad7080afb0b087e3d04d1965bfa9e91030af277e3e897
MD5 b9524f3e6ac7ec3e11c7d5db35683e37
BLAKE2b-256 d11d1633c7eb37f3b6f76c7c6928462062c2b16d35f30661335a8ab910ba991e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d6195ec90e7be7c68b3e0a253a5b5f912c2a2a5613d3c125b5832fb95eb19ac7
MD5 0e00d165ea625f42b3debd321850bcec
BLAKE2b-256 8b3a1b60a1050d7b519d4cb490f43e325647151788a089c0749815b35b001cda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e4f29cd12b333c5b7093d1c06a86c4fa4e74a20202379545a4cc9aca5a7ead6d
MD5 bf6fd12b68d3d76a5afef2b7dc057751
BLAKE2b-256 138b56088fb985897357d4d140e82385e1127c6ba9b736f2804023df432424ee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cfbdcb0b40e66502ca72935ce16c54abcd1772beb42615ca61b92f618ca47bd9
MD5 e57209c78159266f1962f6d8be08fd15
BLAKE2b-256 1c6475beac1bec185b612cb303dc1d2c4a749c5ad9f0625b3e4e95584e150b95

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 48b36f9877483730b5fb3cd321141444a3354be85b75f3f132199c618f248451
MD5 5752a397182932ec7495819e23fb3875
BLAKE2b-256 8305a2a70672dfb5124c6cff87e512dd69190dcf8d857c8d9462d648303fc913

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 1056ed32659f92e0c4512c58b1c67721f5671caf59d00e247ea86c49ff9cf930
MD5 23fb09c71dcea07bcf4a99ce62393994
BLAKE2b-256 69cbc13b28e513f32d280a485059c54995e9244c6fcfa5d1ea84967e63149eaf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.43-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8d6185d80cf1ed41487e35af232b3af77a11a844fd631e2cc077ed1bfb4d0491
MD5 517a2da14ae92386bfdeeacb5d142583
BLAKE2b-256 94f20c07f444fb7100885b9070489bd060cb0719ac9f07367cdf96d01e0b7ac0

See more details on using hashes here.

Provenance

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