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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.51-cp313-cp313-macosx_15_0_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.51-cp313-cp313-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.51-cp312-cp312-macosx_15_0_x86_64.whl (665.6 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.51-cp312-cp312-macosx_14_0_arm64.whl (663.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.51-cp311-cp311-macosx_15_0_x86_64.whl (665.1 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.51-cp311-cp311-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.51-cp310-cp310-macosx_15_0_x86_64.whl (665.1 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.51-cp310-cp310-macosx_14_0_arm64.whl (663.0 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.51.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.51.tar.gz
Algorithm Hash digest
SHA256 4cfa9044379a3e9e1abdabb92379651f2206a405d33d4c1e5104407055b2524e
MD5 a277c181ff16ee53674807b1e6917a1d
BLAKE2b-256 d458fea630f4be67382177884e6cf43b02ad67acb854cd20618ea366c305f009

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 42762d45952bd3de8818fd1222fdde1f110d4f306827736f481dfec9269eeedc
MD5 cf9e1444ae2b2c37131e569785678c5a
BLAKE2b-256 202e850dd352d8bea7b4acc967bdd7535cecc934e31a7646c0d8e33b522799bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 51924641ea6cefc833fbeebd2e613e9d62c18ee605444f420de837b7601af05e
MD5 12ef0d15774ff52aab835d6415fcde7d
BLAKE2b-256 d773b320e9ce509f06c07b5b6b962363c25fbbe7293e6c243fc4cef5bbb9f6e9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e788ce61a5394194da168761cf3744efa552e542c180998f70cef6644599aa59
MD5 678a01a928d221ee4f92e07706c481d3
BLAKE2b-256 21cdeb7342c989d5cbc7e29bbb1211a61e1c978166025121f94c06b4ec1f99c4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c766b9a30e8c2c92e4984902dea25170721a4caccbba4f7bb4b15cc432351bc9
MD5 a33414d17fc2c853f62d4c4c9460eeef
BLAKE2b-256 cecaecd5054058dc44d85ceb349e39402fe44f935daa0a6b00ec16cf63c14533

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12f06650734462279a95335eec494386fe1e5682a0bb7cae268348695b75e5e3
MD5 14cfe1ca00d0297739774f42876602bc
BLAKE2b-256 691bcbec97a5b2529e5b48873158e467067620f9a96d5f8a811dbefd9feac55b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7be1b1fabbbde1051a4fcbe5b692a4d183f433d398c5ac218975edb30ecd463e
MD5 e662f3018da5f7d03d40f9587ae79a37
BLAKE2b-256 2735dca976fa7d57b49b17997e8aa6437a45ca3c335ebea1e87a627c4413a39e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 698c91942e8a3b3cd404deed2a83ab33eb09ce7d328e891145aa1ad9125ea7cb
MD5 af7cf2876cae042d7cf10b932c4aab47
BLAKE2b-256 2ff6101a31b8a546dfb39b907785ad9ffdf50c8178c38518b0b5fcdb20a04099

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 4b29095c01660b821eb94b9db490f9c39de7ace85bfa3ef64a9afd360cafa7ff
MD5 7ba1ecd716ab86214f5213b8324cb918
BLAKE2b-256 d17eb5f751ce0a4844c4cc570c2d341cb8ed7ee088df49b4fc38df2ba47828c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 372831869fed0e0b4129304ff7201540c7625a47442406f628dea35f863b1a5a
MD5 6cde361e794135476a9770289c5b7a61
BLAKE2b-256 a091f062473d7e425d0292057f0bf37bcd3ab02204e02e3b63fac2bcecf1ecff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a8378d3702301da1038df532bc9bc4a483c7b1e45e4083728d1e228c1639a90d
MD5 117726ac557cc1c9ea7ae22315e341ce
BLAKE2b-256 50bcccb1cf88ab5362a74113b78dc8325806a46e7436921a6833c801167233fa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 bd0978bd0314cf98110023bc059d6aee40d187a991cbc01054a474634196847e
MD5 af9552ffbd7b6337517bdef1e66a5cab
BLAKE2b-256 ae5d75fb6129ba7975940c676cfe3bfd10609eac2154314d195d86ba59f15d1b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 a47c3b879d563ac834368c1861880cee4fd0d1fb43b09059e09ac930f1e3e08c
MD5 6e3c1844bb6c58831ce2beb129400325
BLAKE2b-256 7e330a5d977be3acd7c0b6d9c7e50b64f3af61a6c9d7c223b2aadb1dda7a2360

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a642fd848a1b44147c7278c05b32917f382b8a6303f34900a1e6e8af6b093c33
MD5 874664a5479b3454dd729102a146d49a
BLAKE2b-256 c5f1d76a1d3e71dc97edd48ca29fbb5979d7a855036aedf473d171c9c44e9595

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 afcb5195f78810e272fef7d54200d89fb21a890a1489e4eabfc4e4d5127536ec
MD5 13e0cd1c738b60778e90ef40ddef3463
BLAKE2b-256 ce95b362d2855b11f41312b05e4c2001df5a1d7df60654b5f7542c105f1a3d2b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4942f82e45d3c06e1b25dbe05ea403cafe1587e8645f241f40ec0458beb45341
MD5 960aa1fba3bd0173b068344a2c572be3
BLAKE2b-256 4e5308abe4d8794ccd616ca6f6761b61368a5f857a693e20bf1103fb84111718

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.51-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 769f52dc70007d4337ad2ba0334fd6000a5e6c1c46b359f3cfe05e7faa5bf81d
MD5 94a37110fe6d58b6772f3a441b6f5c7c
BLAKE2b-256 26b5810b23d2b193caecab8981118bfae195db5f527d77f6837ccd7a28b66d70

See more details on using hashes here.

Provenance

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