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 --pre fastparse

From a downloaded wheel:

pip install fastparse-0.1.0rc17-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 = parser.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

Examples

From the repository root:

python3 examples/python/03_binary_decode/binary_decode.py
python3 examples/python/04_inventory_to_sqlite/inventory_to_sqlite.py --workers 12
python3 examples/python/05_diagnostics_scan/diagnostics_scan.py /path/to/java/root --glob "*.java" --workers 12

04_inventory_to_sqlite is the enterprise pattern for high-throughput work: the parent Python app reads files, uses threads, decodes binary output into dataclasses, and writes SQLite tables outside the native library.

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.0rc19-py3-none-win_amd64.whl (111.0 kB view details)

Uploaded Python 3Windows x86-64

fastparse-0.1.0rc19-py3-none-manylinux2014_x86_64.whl (184.6 kB view details)

Uploaded Python 3

fastparse-0.1.0rc19-py3-none-macosx_11_0_arm64.whl (166.7 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

fastparse-0.1.0rc19-py3-none-macosx_10_15_x86_64.whl (172.1 kB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fastparse-0.1.0rc19-py3-none-win_amd64.whl
  • Upload date:
  • Size: 111.0 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.0rc19-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 15f3146e036d77dedf40e50005aac9e538ee3e67f9c687643203b0c38c7dc3db
MD5 50318786118752fffae678b9ecb9e7a6
BLAKE2b-256 48a0cd7d1c627636e63743d64fe5f5ed4414067b5719aee56d78e44e3a9a5efd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc19-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.0rc19-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc19-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0af5053f36b4e403202a80a3d67678a86d0c587e662c94968ce7bd4233849610
MD5 c7b76d5b3bacef55c1f8e91bfe3220c8
BLAKE2b-256 63691008215a374b0f2515eb99855410f085290306988fdcde47e4fc1f8c9d13

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc19-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.0rc19-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc19-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb31236a383dda1ec1661bcf84e28a307d1ddbedb4f7e920fc0540428169dbd3
MD5 97d3472a6ed709568b51328df8eb5124
BLAKE2b-256 aa133c8c87c33bcbff05e35ca512a3ec3537d890b6e29fb0f39083d6748ab269

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc19-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.0rc19-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for fastparse-0.1.0rc19-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f7029b3c06122cb991bdf0cd7ff6cb6e379f2c08e9fed41071e9e0d44aee4150
MD5 23d1f29116d3fa2e256fd28165ca8dc8
BLAKE2b-256 4c742394b9f3d51bec262015c1156a6ea9aae66301cfded8861e62acb3f759ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastparse-0.1.0rc19-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