Skip to main content

Python binding for the FastParse Tree-sitter parser library with bundled native runtime

Project description

FastParse Python Binding

Small ctypes binding for the FastParse native C library.

The binding keeps the same design boundary as the native library:

  • Python owns file I/O.
  • Python passes bytes already loaded in RAM.
  • FastParse returns JSON, CSV, MessagePack binary, diagnostics, or stats in RAM.
  • Python copies the returned native buffer and frees the native result.

Install

From PyPI, once the package is published:

pip install fastparse

From a downloaded wheel:

pip install fastparse-0.1.0rc15-py3-none-macosx_11_0_arm64.whl

The wheel includes the native library for its platform and py.typed markers for type-aware tooling, so normal users do not need FASTPARSE_LIBRARY_PATH.

Quick Use

from fastparse import FastParse, Field, OutputFormat, ParseOptions

parser = FastParse()
source = b"class Demo { void run() {} }"

result = parser.parse_bytes(
    source,
    ParseOptions(
        language="java",
        output_format=OutputFormat.JSON,
        fields=Field.RULE | Field.TEXT | Field.BYTE_RANGE,
    ),
)

print(result.node_count)
print(result.json())

Binary MessagePack output:

result = tsmp.parse_bytes(
    source,
    language="java",
    output_format="binary",
    fields=["rule", "text", "byte_range"],
)

print(result.node_count)
print(result.data)  # MessagePack bytes

Decode binary output into Python dataclasses:

document = result.binary_document()
print(document.nodes[0].rule)
print(document.nodes[0].text)

If the caller only needs node/output counts and does not need to copy the generated JSON/CSV into Python:

summary = parser.parse_bytes_summary(
    source,
    language="java",
    output_format="json",
)

print(summary.node_count)
print(summary.output_length)

Use FASTPARSE_LIBRARY_PATH to point at a specific native library:

FASTPARSE_LIBRARY_PATH=/path/to/libfastparse.dylib python your_script.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

fastparse-0.1.0rc15-py3-none-win_amd64.whl (110.1 kB view details)

Uploaded Python 3Windows x86-64

fastparse-0.1.0rc15-py3-none-manylinux2014_x86_64.whl (183.7 kB view details)

Uploaded Python 3

fastparse-0.1.0rc15-py3-none-macosx_11_0_arm64.whl (165.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

fastparse-0.1.0rc15-py3-none-macosx_10_15_x86_64.whl (171.1 kB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file fastparse-0.1.0rc15-py3-none-win_amd64.whl.

File metadata

  • Download URL: fastparse-0.1.0rc15-py3-none-win_amd64.whl
  • Upload date:
  • Size: 110.1 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fastparse-0.1.0rc15-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 2a66d24624be2ba2cafb135426e30370145f1f25015c998fc0cebfc287f67d3c
MD5 8a3885e0d193c73fb90ad43f1d6b54d2
BLAKE2b-256 09652ebbc40f7d979f08982bb0add3830a1f2a1e0025d8ff06e1a07071a895e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc15-py3-none-win_amd64.whl:

Publisher: release.yml on natan-sysview/fast_parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastparse-0.1.0rc15-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc15-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 32442b9e8bf27e40e73df6af02a7fa5c65ff1f3ca4ef036db50f452d9a8ae41f
MD5 a098219275d061a30040ee5f9b8810b9
BLAKE2b-256 f79fbf5bbaffdf89da12fc71ccdc3f7256df77f7789bce58b6da8a09c2cac0f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc15-py3-none-manylinux2014_x86_64.whl:

Publisher: release.yml on natan-sysview/fast_parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastparse-0.1.0rc15-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc15-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 487f11aa1ba77aa4401b21eb1b5fe191a469b80bebc98c3a16b4c789da820d50
MD5 d996677b454249e76e38dee95ceb519a
BLAKE2b-256 6b5e3dc2aa58a8c0da524d4480a64d57a358d619d8e7ff1adf77546c83516e7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc15-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on natan-sysview/fast_parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastparse-0.1.0rc15-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc15-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 bcee793604b901dbeaddcf2ac6c53b38caa21df4b48ed74331466b0fd4bd4ef7
MD5 49251c95c8e828f299ff2d0f866a5a52
BLAKE2b-256 0a9308cdbd4f35efc0ad77d0a9a4a65396ea0c46ddede28bb62c6da581d2748b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc15-py3-none-macosx_10_15_x86_64.whl:

Publisher: release.yml on natan-sysview/fast_parser

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