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.76.tar.gz (92.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.76-cp313-cp313-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.76-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.76-cp313-cp313-macosx_15_0_x86_64.whl (666.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.76-cp313-cp313-macosx_14_0_arm64.whl (656.8 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.76-cp312-cp312-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.76-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.76-cp312-cp312-macosx_15_0_x86_64.whl (666.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.76-cp312-cp312-macosx_14_0_arm64.whl (656.9 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.76-cp311-cp311-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.76-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.76-cp311-cp311-macosx_15_0_x86_64.whl (666.5 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.76-cp311-cp311-macosx_14_0_arm64.whl (656.9 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.76-cp310-cp310-manylinux_2_28_x86_64.whl (5.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.76-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.76-cp310-cp310-macosx_15_0_x86_64.whl (666.5 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.76-cp310-cp310-macosx_14_0_arm64.whl (656.9 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.76.tar.gz
  • Upload date:
  • Size: 92.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.76.tar.gz
Algorithm Hash digest
SHA256 3a81abbe45097ac89ee03c2dd26c502ff6b30520a316b5752823dfae3b98a296
MD5 ba121b8f0dfcda071e026689e96d6888
BLAKE2b-256 574ea599bf350a6e61d28d7da09ebe90699ea5f8a27629d523e1ca1da21602ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 17ce2de5d3c739fcb9b60bb4d373d79e778467be08aad571b75f174c6a5e2571
MD5 1bc0e6510ecf7a9dfac4c4e01f24cf2e
BLAKE2b-256 3c5c9788492b5d2f9feac6b601814935bc1d645c642874b1126cde32abb189dc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d58146f9aee7e09bce6ef906ebf3226ccc36a04c4de79d4392200e50070a12ed
MD5 85184a3a11de6d5797abbbfd33486ff4
BLAKE2b-256 4ca6c70a36d92f48a861a5bddc60ef242fda505d0c268d8b76eb343600860816

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 0e1f774b142d925a4f6b4bdb3eac6cc142e2006d753d3b445aea312f92312854
MD5 a93fce73487d8e7a009c6aba5ece303b
BLAKE2b-256 8cce42d0985ebcf4fbe903330e8d11d169902ad84d8397c810a87bc1eac2e7d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 142b9c3c600a21d1d97d85d735350bb28a5a09268f45f2e583b50f9eda9ae2a6
MD5 5171d63f03e500809ac8993358ab8f82
BLAKE2b-256 9238a41a3fcbd027d79d84352b8858612277512539deb6abe988c9e895fd46e5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d01ecf1d47c706acf65cf2316bea95992bcc22d4236d8811f070522b9a4f5a60
MD5 0fe04d78fd251ece8b40ed155bc3350c
BLAKE2b-256 ea2cfa9e6a6465a40294c8725f923c64d12a650cc7ac2b3b4937b94dee7bc062

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 21c92d4ba4b5923039a4f2fb1a2304f3b5380f3be4c10923fb4cb585c45a08aa
MD5 23f8a3db3866225f620ddd0444eb03dd
BLAKE2b-256 95bc00e7f865d5bdb52730f41fbe7258d6902401af1e3a897bc93f036ba38364

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 44864811f90e6b8a2d856dbf062068c36da09f495bdc267987724fc4fb7aaaa3
MD5 9541722c49c433cdd4a7503f58cda182
BLAKE2b-256 bbee59e33c3c5ea22329fb61184010ccd835b6ed966618aa222ed2e91a979599

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e6bf98727376a4b7945c1f20ee6d12058586378a1a543e3a96e5bab3801f695a
MD5 2665215c9ac11188779849fe8fd60757
BLAKE2b-256 e1b1e1a0e1b20468f66a2ba7d2eabf8a3eb67fa333bfed2a23055d17822814dc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 77431b6db9f3f218c6da7a19ddf7d25ac1f203f18520af29799dccf3dc86b33a
MD5 219f37c445ecef216fd190145bca97dc
BLAKE2b-256 13618fc7587acc72707ef5b5d5e44e6ea0e236f65da9ce551b6f269543006c81

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cdab37ad5a6035641ba1fb2591954c2b50fe52e1a240b3a9bda8b47c0ca6b9ef
MD5 3c99096148b8f1bdbab44c9d86afe08d
BLAKE2b-256 99feb5f02979a4ab2921959713116b0733bc44478b7bf376f953da59b9821c92

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 582213b430c31fd42f9077ada0a6ab2b12150a51b3e58dafbe57b96d78f0ff8f
MD5 cc32c6aff8d747eb103f08f9fe41979f
BLAKE2b-256 14bffda6b4821974c15491e50866403a2fb3f3a824c273b9e697d85c55b528f9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 481af40b2e7dab514c931746ba2edd8a14a97f2f7ccc4aaa3fc6760e4453a6c2
MD5 cfc566af51d63a6b934dc8afadfca92e
BLAKE2b-256 64429babae892926e99d10ce5777073c5a88e02a096173f457937f295e7793e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 42422dd0c69bb642c06c8cf565e3813c9f0f78861855957c43817a335949e87e
MD5 f7f42aec68f6f5833d69ead7f730e52c
BLAKE2b-256 4d742afb5f03543d3235d663f3e4a128feb844bc50d1af2cc73dcb462a9af6b7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 49cea688056919d6115385ab3260f0f2f56b4bee8fcc126913f7b7dc45689690
MD5 918215ecc5c7de542d6fb82636d55ff7
BLAKE2b-256 3edaf5d62e1b6a74ca77615a169f7f2c8b7f71cada19589c266a960585c644d2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 c82e47754a3773e6ac43e4d799b33f458985d6ea6390d3ee6ccea92109317c17
MD5 330dddf71a226ad2bc1ec51fe07153d3
BLAKE2b-256 08736da55bfbf0ecd585fd246b906d02c127d017a528efcdab6eba508bb8a120

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.76-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d86456d1a5c55e179650e3d79456da53055720d6b5693222ed1744b796892781
MD5 465ab09069e7259b5f6b3347cd9438bb
BLAKE2b-256 c83f07b8772b20f433c93dabde5d1d6728bd6c61da4422640b5c1a263c498c59

See more details on using hashes here.

Provenance

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