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.
  • FastParse can execute Tree-sitter queries and return matches/captures 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())

Tree-sitter query output:

from fastparse import QueryOptions

query_result = parser.query_text(
    "class Demo { void run() {} }",
    "(method_declaration name: (identifier) @method.name) @method",
    QueryOptions(
        language="java",
        output_format=OutputFormat.JSON,
        fields=Field.CAPTURE_NAME | Field.RULE | Field.TEXT | Field.RANGE | Field.BYTE_RANGE,
    ),
)

print(query_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.0rc31-py3-none-win_amd64.whl (144.1 kB view details)

Uploaded Python 3Windows x86-64

fastparse-0.1.0rc31-py3-none-manylinux2014_x86_64.whl (191.6 kB view details)

Uploaded Python 3

fastparse-0.1.0rc31-py3-none-macosx_11_0_arm64.whl (172.8 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

fastparse-0.1.0rc31-py3-none-macosx_10_15_x86_64.whl (178.2 kB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: fastparse-0.1.0rc31-py3-none-win_amd64.whl
  • Upload date:
  • Size: 144.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.0rc31-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 97ba72ff5e89aa7ff0fb4b12d16d1d76e02275bf73bccfd15ab4afddbe964762
MD5 fcbf2a59ddc5310eeb198b380d0aadbc
BLAKE2b-256 21eda06c796a75a60a2ec0a343225ca43157e043cf38dcfc7546c5ccdd5ea989

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fastparse-0.1.0rc31-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ff93bf003b1640f3cc2fbb8cf736335efa8d359eba64fe797c1939de1927d2e2
MD5 e0724ac907b6aa18f9a19282333b5f02
BLAKE2b-256 172175fc88d161b255e738e321e39f37123b5798b86f6c80e0d06e83a6c0f6fb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fastparse-0.1.0rc31-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5da6e963e1bbcf3bcd4f5d8bbad7babaf1b2ccae44d4a297c20e44ad9a1d3853
MD5 e99159fb76fe533d2b18a23d9caee100
BLAKE2b-256 682b4281d65afe0199d7d7ca8b26df055574b81a62b61c933d376516b56a368f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fastparse-0.1.0rc31-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 671716090bae749ffbfa7e0deeb142882e1982e39abc71427683c92e56c60ae0
MD5 650ac1710b76cfe2b6f4586d0098c3a3
BLAKE2b-256 41decebbb7b61d876f492677072bea6b9da39b3a8d3d87c81ed40b4b913fd7c0

See more details on using hashes here.

Provenance

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