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.17.tar.gz (69.3 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.17-cp313-cp313-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.17-cp313-cp313-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.17-cp313-cp313-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.17-cp313-cp313-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.17-cp312-cp312-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.17-cp312-cp312-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.17-cp312-cp312-macosx_15_0_x86_64.whl (568.8 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.17-cp312-cp312-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.17-cp311-cp311-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.17-cp311-cp311-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.17-cp311-cp311-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.17-cp311-cp311-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.17-cp310-cp310-manylinux_2_28_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.17-cp310-cp310-manylinux_2_28_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.17-cp310-cp310-macosx_15_0_x86_64.whl (568.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.17-cp310-cp310-macosx_14_0_arm64.whl (563.7 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.17.tar.gz
  • Upload date:
  • Size: 69.3 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.17.tar.gz
Algorithm Hash digest
SHA256 f0aa7b218d76ad9ad20342b3f176292f113fd6c379c2b657b64ee21653c5f49a
MD5 26d2cf54ea7f660e2dc64b4f7750db4c
BLAKE2b-256 dccf8ef614a12ce99d83770b2ad5ed45a1aeb73b279d8c6d8c8480d80b11d285

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 960335a18182a29378f6a70812ded262bc9a3bf24ee7b1cc255c08e2809e4319
MD5 ff01bf0b43e888afccf8f0fd0c74c86f
BLAKE2b-256 204a5b9189f12a4d15d7e8178c7c9b2a1d2b47caa5ccca3a2972516fae32c3f5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8791e349d4466a2d5ae39ed3bf71b851cc46418b62d60b22f70c48c20a32342a
MD5 0a2703b005d1b9866d9f94a9ceb254e2
BLAKE2b-256 600f2f23f1da029976159641f12f807ff7239291e7d617f82136965509bc48e7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 8448bd22b77e9a259f8557d56bc44d6b076a268fd4829e2060b84175bac2fe60
MD5 d93111087a4d1b312aea0164915e37b1
BLAKE2b-256 d95b3173cdad8e0b9af6fd22f903b9a5b4b0cb2eccd4783c367a231999d3dbdb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 879f6ee8dc9e177b4d0b451958a993a2cf0b5f110bcb5fd41e4a189a82613bf7
MD5 dcd4018f1c823d755262f74b2644ae29
BLAKE2b-256 8c286649b492fc54fa321fdfa7aeb5ee6d6ceb7ee0893f89981f9eaf18fad3a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 52d4a22fa0f4b2be2f46534d9fb3b2e9e589f17672419aa80d6ee69e07024afe
MD5 e557c36900eee828346bd9fd882a3163
BLAKE2b-256 d0f827ac2b614f1700a93ab1dce1390c1820015df37ed72f2b5bc7657e9d93f7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 b36de15bc0dffe7e31f9a4c5207f55f6cfb880f859c76a52f74f9b7caf43fa2c
MD5 f856eba084541d1dee3821e18795832d
BLAKE2b-256 a6c46da4959a083281197f62bbccf869b9e1b83f348ca887513d9add70fbd5bb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 d10d29e585cda6e30d6acc911004432a1d0647bd53cea833253e02231066db69
MD5 5b8372bf84ec9f3d2ea34fcb0fb21193
BLAKE2b-256 7624c0900a192a451f1dc9a4646d39e47cef643cb98c81f430a0fc703b229165

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6c735262968dc65cbb04a266a4f59d02b52e27f5c69e0a0cb3989a2de3d9a52b
MD5 43d3e650e8cbca738eaafe68cb23f74b
BLAKE2b-256 cbedb9b06320447c89353f19354d175c5a20f2945e9da1bbf7de0b58ecd91813

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 60ac562de3d3548f9eb140781731da5f930a54781ecb6883a1748022221bbd3e
MD5 00926f873a27a42ac18a6da55d53985b
BLAKE2b-256 e9f6cd32490ef2ab071947cfcb90be3ade706e885fc06d701ec91c872719a5b2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a51b4065886a1c5e8dca42004e08eefe587a53c89f26889a00ea632416e9f2cd
MD5 cc6d3d9d15805aac8c9d1a2c4d632b36
BLAKE2b-256 ae5fcb347b384435c0b16f908950aca15ae4ef9de0b4e52b02305e95d98520c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 721e5d286f10e707a913c3ea37b9eb597a8a52360e3b3b35df812b828d1afb5d
MD5 f60b5ffc007a2cd056d3913c569478cc
BLAKE2b-256 d9737294705baf5b417ebefea5d44426dfa33738d2d29465381a70b6778f4757

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 05fe7e14fd4b3e6ec0ff8b895d250bf694a55e9badcf390667fb3cd6907484be
MD5 0b3a2f2ed808120a75f39d0f8abc1746
BLAKE2b-256 06b21cc9d26799e234c9c200f3f09e4a014d5e38c411c4c15dcacc0be57494f6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1c11d102872e7d9af48db4ece3325f0861ad21fb9ec7cd646fdd0a287434d77
MD5 686b7b54b8a5575367b8e3eac872531d
BLAKE2b-256 63b61e987806354e3da07563827acc25bb3b0263e1f5b5fe2fb11a899ec1aebd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4cbd2299b5547fb23bec5ca7a127e28a4a5b2cdba6e063854700faaad0da19d5
MD5 38746d99e6f4d359300c0e81c740db15
BLAKE2b-256 a298e6500acc5039bbab244d4fcd381ce905c1cd3b6115c193882845fc4352c3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 93651e560e4badac864ec3bf35f722847cb954ceeb15886c79e1e910066ef397
MD5 1b1d028d1118becb29eed800fc5270df
BLAKE2b-256 b402331e1c2a3a719e2920e65b5b92acdb42410bfd180df2467877c18f42ed01

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.17-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5f5540edec4a19aa49f068fbdf4238da34fa83669e9ab78e883be16e7f7ba1cc
MD5 ac0d70300ee660bf24df98de08c4317d
BLAKE2b-256 ea15cac8f2fc90b248836f4fd4623aaca0494269dd9989a9ec343b23f3c0cc62

See more details on using hashes here.

Provenance

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