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

Uploaded CPython 3.13manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.61-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.61-cp313-cp313-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

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

Uploaded CPython 3.12manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.61-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.61-cp312-cp312-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.61-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.61-cp311-cp311-macosx_14_0_arm64.whl (665.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10manylinux: glibc 2.28+ ARM64

hogql_parser-1.3.61-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.61-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.61.tar.gz.

File metadata

  • Download URL: hogql_parser-1.3.61.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.61.tar.gz
Algorithm Hash digest
SHA256 5b400f2d3d27e18b6048ca9f9f38132b71c109893e0e2d1f5559a7c37e2e1962
MD5 3b4b474a1ade872af97a410f4cac5912
BLAKE2b-256 aa51a2b6145e39af0cb7d66c8f5215bf587660903ce33c105fef6ae48dc7c752

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a279f6e09335e8f2353e7f0308c42b69786564021b9e368fa392a6d2fdeb7dc
MD5 545f8d6d2b81c6a94196f7a199ef134d
BLAKE2b-256 9b4c4b941dba6b3b134e95713640a5af4602a93a46d719769feeaddda32ea80d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp313-cp313-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a1b83d0432cd84c5fd3a702e86b93b5f1cb83f2a847cce5d5c7d4329e0cc9845
MD5 210ad9c8bc2f67424a669ba2d8a6ba35
BLAKE2b-256 5943f2c5f02361d4ba25d491b0f19ce2451c9305189cea34e5894da7ea3504ca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp313-cp313-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 f0b6c5f1ae6bce5147726015e302c0a27e11c5b73073bccf658577ad72e6dc42
MD5 7133d1ec2fd35fbe6826c3a16ca649d1
BLAKE2b-256 7554ad89f3c80b7023352c93ceee642139e3f6cf681c88aecea196e9a3d72324

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1def52ced845001a5f552dce9099c20a54a3121cb579e2c67020dbc03c4dccc5
MD5 68ed7ea235466fd908012677ad6024a6
BLAKE2b-256 1c6eae8846bb7f67f3031324697f522fd19cc2cd413d58c16f45493352f1d241

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c5e3abb14429ac8a3b156db89c066269143f1919b0b4dabd348415b09ff72440
MD5 80ffd798a3afc64c5c436ba7d1ad0211
BLAKE2b-256 99c27d0207da745d13ef74afde3478b2b1814fdb8014c429ee7e289ff6b1956a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp312-cp312-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 27c4318407be3500a4633ea38a0b1628f42f98bcd1709582402747cecbf2cb71
MD5 b61ff0689f13d9acdc3b871f4d53e995
BLAKE2b-256 4bbf4c98082cec13551ec318d627b079b6c6b1ba9e1a0e1995493de9bece7645

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp312-cp312-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 ae123c0ceff50397bbcd27d28a2c50363226f53ca2bf7a00e2343d19c5a3f078
MD5 803e7c5d6769e82a30a2c28b9aa4a332
BLAKE2b-256 d0d6ab0421f504849c785f10e2c74cdba83192b68f8b958523e31fd936e9b176

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 e76dbbc7a12de56edf8d45c4a8bff014a0f8803e87c84c78ba90eedccf32262a
MD5 6bb98cd829b2371bbe81bdfd3d7b48d7
BLAKE2b-256 d16c81b7d6baa381f6d04cb97f70c324c89eb6a41e3232dcc748142f91e9aee2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55f9a896938142db371765216fc29c28220f5b0b5c57c5ad301adac891e73274
MD5 ecc83394efba1d520797399a00a53f01
BLAKE2b-256 72614a130ae2941e8d41aa0d3af13ebf42c1a5b4b8e473ef9dee02d058250cd0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp311-cp311-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0927bd0efa811924244ddb208872ed14b939f9870dfc68a789b2a654d52d6ea3
MD5 1a9b983b242c21e0499b939630f5aeb4
BLAKE2b-256 bfab6358b22690e53854489967889d6a7483ccfac09d09d8643a890f63dd42a3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp311-cp311-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 e8c42ebf9d0ff3638411c1f2eadcbca9ba961b6778fb87e381ad38215c7de89d
MD5 7c98fa3676fc79487deedd4d815815ef
BLAKE2b-256 7419a1fe5d983f9377f4191ee19cb5dd612f8575481ad5cd8af9a4cb1cb06637

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 6d9ff88605728a4c68a6f097ab7bace41b96d5baea14b2a28795b9cc2676ffa0
MD5 49f004431d69c9e4bb117a49a6aaf71c
BLAKE2b-256 9a8bbaf529f23eed4c91f68fecc4fbdbae1c94295c1f37ab5b2378f8cb52138e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 186c67a2f3e565772e790052a1be5fe8406bc14eec9dac79b402d378047110bc
MD5 1887dc79e4350dc24fc717b5cac6fcfa
BLAKE2b-256 c90771650fbf8bee9c42ab31d4cef625dfb914a56e394a4db678e43d48560ec0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp310-cp310-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a6e792a98a5b64f677d4f87f6a8930e012743a545a3c33ba425d4ba7ee33f281
MD5 ce72455209ea8d4931a51de7cebc0ac0
BLAKE2b-256 22aefe11930a84654af5b9183dc54b6ba978d2bef7a2444ca5b290e2d8275924

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp310-cp310-macosx_15_0_x86_64.whl
Algorithm Hash digest
SHA256 fe00158b6d144e2f15e04d3b6cc0ee9e7be2791f7433c1deba0850b5518f4c13
MD5 87ddbf46528618c1a0cd34806a4cb982
BLAKE2b-256 0190712ed4cb1f514e2bf603bcd2cfb59f44bc58ff9a70232d72ccaced112337

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for hogql_parser-1.3.61-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f5eb34b031db06d6d46dd38fe2a4018a1bc3f0d54622258e68a57853846d1b85
MD5 85fa71898ae26dfeea96f1dc4055e21c
BLAKE2b-256 5ebc5d8c373352031cde0592a94b5412939fa83f662870545fd54ae46e510b09

See more details on using hashes here.

Provenance

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