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.62.tar.gz (92.0 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.62-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.62-cp313-cp313-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.62-cp313-cp313-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.62-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.62-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.62-cp312-cp312-manylinux_2_28_aarch64.whl (5.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.62-cp312-cp312-macosx_15_0_x86_64.whl (670.5 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.62-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.62-cp311-cp311-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.62-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.62-cp310-cp310-macosx_15_0_x86_64.whl (669.8 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.62-cp310-cp310-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.62.tar.gz
  • Upload date:
  • Size: 92.0 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.62.tar.gz
Algorithm Hash digest
SHA256 f2dd60629ea0dd112a940abec3e1214bd3cb5febe3c40a99c775547e1dc45587
MD5 1e10f2d633f3a27a57c4254c1b908329
BLAKE2b-256 684dd3157bc0d2ee5b9bca95f71e11fe967776a0281e28cc5187083bebcf2714

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0fc85cc0ed6feb7f15d990c5b586f3780d08f0a60bd9097f8bc9f5265b88cb5a
MD5 851d5727facc919192f565ef3fe555bb
BLAKE2b-256 3dc792b1dac0d0463fbf285be6e3f419c82feb394f8a38c8b59812761456e448

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d17d9da28365743b1391505c07cbf177f740dca9d0d942f0ca0f9bc26bdf5453
MD5 990c7d65f90cc95dfd94381e94074581
BLAKE2b-256 fe74a5b21633d9d55a8831547cd98da0126d5f6e251514140105963c64fd158a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 14c76a389b17b4b75e784f6db2852145620795b4a107e8a6911d15f4e600d182
MD5 fafcdfb497b7e7ce8d8d294e5012a277
BLAKE2b-256 4afc9f8f8998bf769ca28642a601bdd8d3aa57c511b393a7ef243d3bb7b9c23c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9d2637543bca8d915040ff8ba3e1ae10786621de3a3f5e5874ca5ff494f10978
MD5 10ba122e3ba6123a395d0a0f88b26369
BLAKE2b-256 da16b17ed8379a1627f448fbac8f0f6413ac31725a258c37cc274a2cbeff0a23

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 719f7fc7375c82fd35e32fafc919f7784d4882f48ab5fcbc06644ee54f564b09
MD5 9c10badef5772c79881f696747660c16
BLAKE2b-256 11aa506fe579f2a1af4081be1a5c60be186c2f53ee4f38a6367bcd2a8cb71f52

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dec37ed9477bdbad8aa981271e74b58b9c21a36b1ddd44b7899974911bd7f5b5
MD5 5373b8b6d373cf6075452d261b6f9b7f
BLAKE2b-256 b70f2a916c8d2180a0ec345deb455d1b313718c86757662a5378f8fa586b1e45

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 48b1fe866079a5f72a6c740980a72c3d7943405798f3a96b09bb2b61bedd97fa
MD5 a45d6250a5d594b7b4aacb35b65152a7
BLAKE2b-256 55d75fd4f29d56627d2dfc0c85af2b49a8b39a405c1a75c2b251827a02be23d8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0ed57abe0edb7f44a59718a610c2ff08bbdd9d2adcf61fffdc79d6caff24c370
MD5 2a2f6fb121c2de19a298e408b10f635b
BLAKE2b-256 fd37521053b00f7a8dbfce59beb1d3775ef8f780a6386523663986426642d119

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 86605067f55282536810c431af58c21d5343f8c68bf56131aff6fe97d4afcfde
MD5 2b7fd9a492c3ea9e7dbc45251c0d20ac
BLAKE2b-256 d86a231cc1106ebf718786c49820d5305852ad6cb7aaa5c73a6c977700a73263

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d1c3fcd2dc3c885987f2dffd588cf4b93cf6212a0040d5eec7a2987a60a55d1e
MD5 53c88613930ac311e340d338a81cb114
BLAKE2b-256 2f7803cb7e24d05c38c3c609a4f9e060d304b54bfccb5b1c35a53775dbd5a740

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 145ba73cc32fd5c083e8033dc0a7dcceba85cc3af4be8c5a82fe7388ba088612
MD5 2c4eed90b78724e8bae1bf123110160e
BLAKE2b-256 614d50eb6f0799e6c65db80a6063ce72eccfd19637f4bb5327199a9860c22bbc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 08936daf710fd3ef171fc31580b423e8fa45454043bf024cf73f8e4020070568
MD5 540c775df4aba078893d980b5c13ce88
BLAKE2b-256 a3ae58f41156a1a8116a5527f1774732e6edc3f08a3c2bf36648f3dec2dee415

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5bb9e27e65eb2fd10ca21e8a783511aef14854a09add7c87e9792f734725ee6f
MD5 202ad9462f0d02457cabbe4cb578bac2
BLAKE2b-256 f72471fe1eab06852c6ce381778c72f4a372fb53edef483b988a1714439ad7a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ed3feb765753b8c5ba63f2f922ae59370fbca2c6ea04ca2e21e797ef373b05fc
MD5 0c8bd5e1258b69183302fadcfb887e1e
BLAKE2b-256 fb1b34cdb259fd77bc2a22f2e32a58f46d57d1feabf863c566181aa22a014987

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ed803627fbea27e041cd7ce94a01b1eda34c885b9d361682a5d08463337f1faf
MD5 32abb98962a9b7c550e8d9bf4a079082
BLAKE2b-256 071018d984d337be502ad059ea7c3ff00593cdbd83401b74ff0670e83f766aae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.62-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e11897122ad75933a1a26922376abe9923ae7adced4a18fba21980f00f20e90c
MD5 67698d55202ea605d9cfdaf97251c828
BLAKE2b-256 ed805de3689ca2c1be487c65fac7b4d6403bf59ec7e685145dfcdc0095e91429

See more details on using hashes here.

Provenance

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