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.50.tar.gz (90.6 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.50-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.50-cp313-cp313-manylinux_2_28_aarch64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.50-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.50-cp313-cp313-macosx_14_0_arm64.whl (663.7 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.50-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.50-cp312-cp312-macosx_14_0_arm64.whl (663.8 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.50-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.50-cp311-cp311-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.50-cp311-cp311-macosx_15_0_x86_64.whl (665.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.50-cp311-cp311-macosx_14_0_arm64.whl (663.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.50-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.50-cp310-cp310-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.50-cp310-cp310-macosx_15_0_x86_64.whl (665.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.50-cp310-cp310-macosx_14_0_arm64.whl (663.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.50.tar.gz
  • Upload date:
  • Size: 90.6 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.50.tar.gz
Algorithm Hash digest
SHA256 9bb9ae62bbe078a1352290580cfd7cf7bf3108571b63ff8b97f8b9dba7c64672
MD5 0c56481b4430d1b3ae663f1aaa2cbf55
BLAKE2b-256 131c04038be4a7e255f1528ae12926e26585bbe069083b19714c74ba8321faba

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd21f89cb5c663950c03544513ab1c285364afd62521f20a5ffeb8e633a325ac
MD5 98d9f954a62620834c86a0d26931cb0d
BLAKE2b-256 b74de9682bb8cc47f0617833c21c196a3720a8da10e09f9744fedcf5c7f90297

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 435b0801f35b7c50181903a5e81a7f378a4468d0882fb4b279576add2c56ed1c
MD5 6fcd127e97e8d7d410e8028d6ddb75f9
BLAKE2b-256 464e4b264cdec22d41dbc0a1cdbc0b91fde53ff946ca1adda29ed4285b4e91a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 7f418fc68a4498334c2812efdb42a9682bea4e840437f7213d6bbf17c72d5e02
MD5 f514607417160a15d17189c8ad70f743
BLAKE2b-256 7d4bbe77ec640eaf59b739681da98bb9f951976a42f5405684f2f2dd3bfb172d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9bdc9f7bef1e9783cd7a02fbc94885d9492199d5b5f953e99f9632598a26ca06
MD5 e5ecc2273c2bf4702660856b87f32445
BLAKE2b-256 6c86b96f9b6454da80f4da11bacf76612af0f063883a728ac0521353ee9fd369

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8cd8a58b123ba2fea106c7fea8210faac0fddba00bb61141fc74438132bb3dab
MD5 0f6ae643a5b641617df4b172842a2d30
BLAKE2b-256 a97341f85af906a0cefc742190eaa6a650925279dde3b38de5e196af34b5a1f0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 916ae115d1cfaf9566ced49f002e37faa4d523cb013989afe3c4c13cdb42a2c9
MD5 50eeb49565a63673b577eb4b7b955458
BLAKE2b-256 c2e734aeb1e8ea1a27e470cf2c3352934158a746ed5b9626c46ead5359777454

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 538f60db44b90540b7db8145f7ab70bbe66cc1bb21e9a65342b175980a8b6896
MD5 ef6c13b3674aa8d5a400b284c6f3c2fc
BLAKE2b-256 cb82cf237e6da679f8119984f2673fc7f64ec8707c9f36db08ef0c9c6a536f08

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 19a1d3d102c612e4d262ac0da10f9c1c1d0c2032b4e6c12e36319fbb7c1797ea
MD5 e98f362acb388266371f9a89f3db454c
BLAKE2b-256 f3385089a6006bdb7729921e3e200b5966cd307b94047bead04e885d86ff8899

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c518fed68cfad5aeb63a8fc0bc3408119193d89538370f46cb9c0ba6159ee409
MD5 f429ed25e0326a250673e79799dd1889
BLAKE2b-256 33efc2be1f89e802655456409482803c65fc7ef4271dd5f87d24e01a4f6e0d71

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ae16b28d1f718869c9c90595b29492c9a58cfe186d15b5fab2e14b6ac9dbd1e2
MD5 bcc6195d9805df56368a8618c38abc1d
BLAKE2b-256 5583c69884f1a7773a831e70007e4fa04b3b2fce8e1fada52d83413d8197abb7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 5aead37166aaab8a123698555c0c92a160176a0a48bdb21a95c1bf87ec58802c
MD5 aed1cde78617f57e7e125d4bf4fd6820
BLAKE2b-256 2dcf92b4144241ce221a94a0d5fba2388282f491748431d69d70f60f09e37afa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 8dccf8a9a962aef21f509ec23872f84f46be08123ff89c8f48a71fdb9dcd6100
MD5 edc462867912a1c0fbc41af18d800658
BLAKE2b-256 52424dfa43b531d7aa8c2b2af74ce852efd067e28392b20e757b7200a5ed8c70

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 255a5078d06c37973752bfdd9f71ab30acc4d1bdbfb880006a86d2960818dd87
MD5 f02ab88170306d75ed5a060dc08250aa
BLAKE2b-256 0241d1e169c5e43903d5b5ae7f05313a0339a1f049b67c087bc4fce4f39f4551

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 23b8d8bc8d897a4af0a04e09ea515bf5dc6cbe313930d95e261075e46559b1dd
MD5 0ef455eaca02995fc57d0a30c7400c55
BLAKE2b-256 030be59883e4ea4a6edbbd730d7634eaf26f1e9e2298a55b09dd18db76708046

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 6d18ba84de36c3b99c8be1159e7daa3ed988612e0d352e2abc569820f8197d08
MD5 546399e59b7c8e3b96aa9700b45e5ea2
BLAKE2b-256 aeda923a365b833d72fa220e391180f6f83cd7da80ce8320a13de874e5524ea3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.50-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 72c256a6c3178c28fae71e32ce92c0a6a84c804574ecb0011a71f2fa80c8045c
MD5 0f94795e0c1b4474a192ee64120e69fc
BLAKE2b-256 3363c330934c05f29fcf127df568dceae321b4f965cc9a6ee46c110e0ba93447

See more details on using hashes here.

Provenance

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