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.29.tar.gz (72.2 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.29-cp313-cp313-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.29-cp313-cp313-manylinux_2_28_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.29-cp313-cp313-macosx_15_0_x86_64.whl (616.2 kB view details)

Uploaded CPython 3.13macOS 15.0+ x86-64

hogql_parser-1.3.29-cp313-cp313-macosx_14_0_arm64.whl (621.4 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

hogql_parser-1.3.29-cp312-cp312-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.29-cp312-cp312-manylinux_2_28_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.29-cp312-cp312-macosx_15_0_x86_64.whl (616.2 kB view details)

Uploaded CPython 3.12macOS 15.0+ x86-64

hogql_parser-1.3.29-cp312-cp312-macosx_14_0_arm64.whl (621.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

hogql_parser-1.3.29-cp311-cp311-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.29-cp311-cp311-manylinux_2_28_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.29-cp311-cp311-macosx_15_0_x86_64.whl (615.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ x86-64

hogql_parser-1.3.29-cp311-cp311-macosx_14_0_arm64.whl (621.6 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

hogql_parser-1.3.29-cp310-cp310-manylinux_2_28_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

hogql_parser-1.3.29-cp310-cp310-manylinux_2_28_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.29-cp310-cp310-macosx_15_0_x86_64.whl (615.9 kB view details)

Uploaded CPython 3.10macOS 15.0+ x86-64

hogql_parser-1.3.29-cp310-cp310-macosx_14_0_arm64.whl (621.6 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: hogql_parser-1.3.29.tar.gz
  • Upload date:
  • Size: 72.2 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.29.tar.gz
Algorithm Hash digest
SHA256 7f83b7db21a6b2120f0a6970103e57fe78d7705b19d1e342049cd6a81062a8f5
MD5 37789be5049ae224c5ee01b87001a48f
BLAKE2b-256 2f3122be497dc492a2fa5d51727e47900e214322f17fa720e2b35b4cd093dae0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2ff6b570ac765bc26979947de0a473bdfa4126dcb08f74dba500c1f9d2d2608
MD5 b3634dc49d9fffacba411ba7b1fbf47c
BLAKE2b-256 cbb7219b80dadb37aad7f06f9eaebf490fab3e3a696cf6e3632b777b0f21dba2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e28a252e71ad83deff92b35618fa594628964486499122925f2274747035ca4c
MD5 74925cd7790c2863ad568acbcf26cb3e
BLAKE2b-256 1248d0151308c92a1614e7e0765f0ced80c8e0fec6f9fcd874dffea2430f545b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 fad8f5f287a1be750f5dab53da55a5a89fda2d546c51a2caa36b48352a3aad94
MD5 8d7184fc4d94f8cb271bd9d3596cf497
BLAKE2b-256 5960034c561bb29734a8f598106c8c2967336d42a7e4951503a290b7226d079f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e1508588269a78eecde3e9d792909616ddc9883988274c27aba3029fd5c34dbf
MD5 f9d5d7747e563eec75914b5672a03f65
BLAKE2b-256 7fe834f4664ca8ebdd0bdedb3a0d7a7764efe73e730018094dda1d4bb74f0d6f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ba55102bf80d5f65f07762c2f1eba7ac843c9e828ba7201452b5a80af384d3f1
MD5 f6209f5a8d6531ee9ff840e3778a9681
BLAKE2b-256 9b016a5f0f43a69af1abe5e7e137c98084c5f0637f6ceda7374c5cd8ac4f5af4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 65879af2c8f43e456949a708da82f7fd64e391123d82f8d8e60ab5fa5d8e8899
MD5 d7cee3246af7f6f6ed3c4d3bfb58fdec
BLAKE2b-256 e99751830b3e60926cbafe29c073b27242e327f563d975cb1e4bb6877302f1a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 4c46457fb76a90dbc8b35e8947e6fa8dee7c84f826e5ceb3159f46ee83e4d626
MD5 62733a0a6f235d3b32f9f1b9fcfd00eb
BLAKE2b-256 08ea63e128455f276b14b0ba3d57c0e2f01aafcd6fd8ec5cb9b99e04acfc20aa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 dca0b1dfd5d809a6cef1fa7605d2653576d8978a9b77ef4b9849603f9b963559
MD5 e4f68a972d1ae2851c64ca299a8cfe5a
BLAKE2b-256 cec162abfda9cacb55d46f1963f4bbf30b917808ae992b30bf8943f7bb1ec68b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 54a2e9db53d2465c50383c2f7490bb17a40e077164d245960f6a81e0755beebe
MD5 768457173912b363a0c819a2aea23226
BLAKE2b-256 ddcc58024b991991274648c853f1aa83c993214bafad0b2b491f85d0c1c43714

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5ccdd3d254461258323da0e79a593d73a751280334fc471d3688282ab66bca52
MD5 efc8a65a0e73bfcafc6855f9da2a6607
BLAKE2b-256 b28ab8b8dd7ce6a870f5fcba7435e7985b34340e574527e112ae31c405ee823a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 37e5a9b121f34f3f6b4ac950782217fac74b91358670fb920a357a6e7fa4dabd
MD5 505966763486955269bae293d24b89a6
BLAKE2b-256 cacc9fb7339367215c69bbf425cb797580894e89d28b69c2f0ca80a3f75f0ecf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e174127b9517909a433a687c70725ab769e78903b57f42838a9d975780a3a418
MD5 ea015d6f47bd7d10784e185e8796d04a
BLAKE2b-256 6704ec5e50daf0d19d96d5e64ed4d306f6cbb7275a5e59f149cbfa68a16db0b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c36fae042e9a33cce99cbdee8c667a4b2a34d3fa3273201c872a6aa5caa79197
MD5 42a6f422ad5d7285e0fd813c323bdd4e
BLAKE2b-256 ad192356830f881faabfb65c2fa7886f97dffb93f48c02d6103c2efb318d7640

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 45daae149621aeffb394715585715052741004b13ad1860de651756490688356
MD5 5aa706cad16401cab06096efb34a0268
BLAKE2b-256 7d3e61c08a0a8ec3ed03cce650aa60cd7bc47ab5ff998545d988bb0cc1e08f29

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 91c4b5c9db9ff0b5e4f12cd992dea1f853deaff04d83bf900d624af865058f6e
MD5 a43019e3586e14cad5618d7a9538fd0f
BLAKE2b-256 d7915b481e3021af853053edbe7e77bff4ccaa6c2461347763adf5dd7d360943

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.29-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 b9f68a5caabed2524d70b5ec4fb9996cc466a5afea7963fc93a85388ffafd652
MD5 c3fbcda33f8c5a2b0e1569d7e4634445
BLAKE2b-256 b821dd9c9cb2a54e3bac4eecc0b7f209c60d6ba8418b8200bcd7097283bce54c

See more details on using hashes here.

Provenance

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