Skip to main content

thrift-parser

pip install thrift-parser

Thrift.g4 is from https://github.com/antlr/grammars-v4

parse

from thrift_parser import parse_file

lexer, tokens, parser, document = parse_file('tutorial.thrift')

or smiple

from thrift_parser import ThriftData

thrift_data = ThriftData.from_file('tutorial.thrift')

print(thrift_data.tokens[0].text)
print(thrift_data.document.children)

or you can try antlr's way

from antlr4 import FileStream
from antlr4 import CommonTokenStream
from antlr4 import ParserRuleContext

from thrift_parser.ThriftLexer import ThriftLexer
from thrift_parser.ThriftParser import ThriftParser


def main(file):
    input_stream = FileStream(file, encoding='utf8')
    lexer = ThriftLexer(input_stream)
    stream = CommonTokenStream(lexer)
    parser = ThriftParser(stream)
    ctx = ParserRuleContext()

    parser.enterRule(ctx, 0, 0)
    document = parser.document()
    return document

Why ?

python thrift parser --> thrift-fmt --> auto format my thrift files in one style

TODO

  1. more ast operate, fake_token, fake_context
  2. other language?

Metadata

Release files for thrift-parser 1.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for thrift-parser 1.0.7
File Size Uploaded Provenance
thrift-parser-1.0.7.tar.gz 27.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for thrift-parser 1.0.7
File Interpreter ABI Platform
thrift_parser-1.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 56.8 kB

Release files / thrift-parser-1.0.7.tar.gz

Download URL thrift-parser-1.0.7.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c5c444ea5d8f07349d275756fc469d1b891ebc58b2b3f8adddfe8ff44b7c94c7
BLAKE2b-256 checksum
How to use checksums
bbcc5ab9c47474732133a7afa4cdd785dde54098f10e31e72886e8042574eddb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.4.8 CPython/3.10.6

Release files / thrift_parser-1.0.7-py3-none-any.whl

Download URL thrift_parser-1.0.7-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c02fd7df41dad79d1ced1ea364d3a9164179215e78339198388970338961853
BLAKE2b-256 checksum
How to use checksums
650691063c22e0534aa215cb443441791d2c0f0828146e55d6ad9a82b488f6fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.4.8 CPython/3.10.6

Security for thrift-parser 1.0.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page